From 2a541e6541220919485b686d392871b353cffc91 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 20 Aug 2019 18:29:37 +0200 Subject: [PATCH] wip #2941 --- .env.production | 9 + .env.staging | 9 + app/Http/Controllers/NewsController.php | 2 + app/Http/Controllers/ProductController.php | 5 +- app/Models/Product.php | 9 +- app/Models/Producttype.php | 35 ++-- app/Templates/Aboutus.php | 1 + app/Templates/Base.php | 1 - config/cubist.php | 2 + config/elasticsearch.php | 206 +++++++++++++++++++++ 10 files changed, 253 insertions(+), 26 deletions(-) create mode 100644 config/elasticsearch.php diff --git a/.env.production b/.env.production index 385c425..b78b5be 100644 --- a/.env.production +++ b/.env.production @@ -43,6 +43,15 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" GOOGLE_ANALYTICS_ID=UA-4339912-10 BACKPACK_LICENSE=YwdOWjeEczPAwy06GzkBJggW +CUBIST_INTERNAL_SEARCH=true + +ELASTICSEARCH_HOST=127.0.0.1 +ELASTICSEARCH_PORT=9200 +ELASTICSEARCH_SCHEME=http +ELASTICSEARCH_USER= +ELASTICSEARCH_PASS= +ELASTICSEARCH_INDEX_NAME=pmi + FEATURE_QUOTE=false FEATURE_NEWS=false FEATURE_SEARCH=false diff --git a/.env.staging b/.env.staging index c581028..cc7b4c0 100644 --- a/.env.staging +++ b/.env.staging @@ -42,6 +42,15 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" GOOGLE_ANALYTICS_ID=UA-4339912-10 BACKPACK_LICENSE=YwdOWjeEczPAwy06GzkBJggW +CUBIST_INTERNAL_SEARCH=true + +ELASTICSEARCH_HOST=127.0.0.1 +ELASTICSEARCH_PORT=9200 +ELASTICSEARCH_SCHEME=http +ELASTICSEARCH_USER= +ELASTICSEARCH_PASS= +ELASTICSEARCH_INDEX_NAME=pmi_staging + FEATURE_QUOTE=false FEATURE_NEWS=false FEATURE_SEARCH=false diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php index c0c1c38..99d2750 100644 --- a/app/Http/Controllers/NewsController.php +++ b/app/Http/Controllers/NewsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Models\News; use Cubist\Backpack\app\Http\Controllers\CubistFrontController; +use Cubist\Backpack\app\Magic\PageData; class NewsController extends CubistFrontController { @@ -18,6 +19,7 @@ class NewsController extends CubistFrontController $this->data['title'] = $newsItem->title; $this->data['image'] = $newsItem->getFirstMediaUrl($newsItem->image, 'thumb'); $this->data['news'] = $newsItem; + $this->data['page'] = $newsItem->getPageData(); return view('pages.news-detail', $this->data); } diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 0027090..3c1a691 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -22,7 +22,7 @@ class ProductController extends CubistFrontController $this->data['products'] = []; $products = Product::with('media') // Eager load media to avoid N+1 query problem - ->where('product_type', $id) + ->where('product_type', $id) ->where('online', 1) ->get(); @@ -41,8 +41,7 @@ class ProductController extends CubistFrontController $this->_404(); } - $this->data['title'] = $product->name; - $this->data['product'] = $product->getPageData(); + $this->data['page'] = $this->data['product'] = $product->getPageData(); $this->data['related'] = []; if (is_array($product->related) && count($product->related) > 0) { foreach (Product::with('media')->whereIn('id', $product->related)->limit(4)->get() as $rel) { diff --git a/app/Models/Product.php b/app/Models/Product.php index 904badd..a87c8ba 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -2,13 +2,13 @@ namespace App\Models; -use Cubist\Backpack\app\Magic\Models\CubistMagicModel; +use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel; use Cubist\Util\Json; use Illuminate\Support\Facades\App; use Illuminate\Support\Str; use Spatie\MediaLibrary\Models\Media; -class Product extends CubistMagicModel +class Product extends CubistMagicPageModel { protected static $_specifications = null; protected static $_productTypes = null; @@ -59,11 +59,6 @@ class Product extends CubistMagicModel 'column' => true, 'tab' => 'Spécifications']); - $this->addField(['name' => 'slug', - 'type' => 'Slug', - 'label' => 'Slug (URL)', - 'tab' => 'Informations génerales']); - $this->addField(['name' => 'online', 'type' => 'Checkbox', 'label' => 'En ligne', diff --git a/app/Models/Producttype.php b/app/Models/Producttype.php index 5613025..b3917e0 100644 --- a/app/Models/Producttype.php +++ b/app/Models/Producttype.php @@ -2,9 +2,9 @@ namespace App\Models; -use Cubist\Backpack\app\Magic\Models\CubistMagicModel; +use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel; -class ProductType extends CubistMagicModel +class ProductType extends CubistMagicPageModel { protected $table = 'catalog_product_types'; @@ -16,14 +16,13 @@ class ProductType extends CubistMagicModel public function setFields() { + $tab = 'Type de produit'; $this->addField(['name' => 'name', 'label' => 'Nom du type de produit', 'type' => 'Text', - 'column' => true]); - - $this->addField(['name' => 'slug', - 'label' => 'Slug', - 'type' => 'Slug']); + 'column' => true, + 'tab' => $tab + ]); $this->addField([ 'name' => 'type', @@ -31,22 +30,17 @@ class ProductType extends CubistMagicModel 'type' => 'SelectFromArray', 'options' => ['captor' => 'Captor', 'system' => 'System'], 'column' => true, + 'tab' => $tab, ] ); - $this->addField([ - 'name' => 'intro', - 'type' => 'BunchOfFields', - 'bunch' => 'App\SubForms\Intro', - 'label' => __('Introduction'), - ]); - $this->addField(['name' => 'specifications', 'label' => 'Spécifications', 'type' => 'SelectFromModel', 'optionsmodel' => "App\Models\Specification", 'order' => true, 'multiple' => true, + 'tab' => 'Spécifications', ]); $this->addField(['name' => 'filters', @@ -54,8 +48,19 @@ class ProductType extends CubistMagicModel 'type' => 'SelectFromModel', 'optionsmodel' => 'App\Models\Specification', 'order' => true, - 'multiple' => true]); + 'multiple' => true, + 'tab' => 'Spécifications',]); + + $this->addField([ + 'name' => 'intro', + 'type' => 'BunchOfFields', + 'bunch' => 'App\SubForms\Intro', + 'label' => __('Introduction'), + 'tab' => 'Introduction', + ]); + + parent::setFields(); } } diff --git a/app/Templates/Aboutus.php b/app/Templates/Aboutus.php index e97ef9e..7a6569a 100644 --- a/app/Templates/Aboutus.php +++ b/app/Templates/Aboutus.php @@ -43,6 +43,7 @@ class Aboutus extends Base 'label' => 'Texte', 'type' => 'Markdown', 'tab' => 'Nos Valeurs', + ]); $this->addField([ diff --git a/app/Templates/Base.php b/app/Templates/Base.php index ea8aa7b..bf41d59 100644 --- a/app/Templates/Base.php +++ b/app/Templates/Base.php @@ -17,7 +17,6 @@ class Base extends TemplatePage 'label' => __('Introduction'), 'tab' => 'Intro', ]); - } public function showInDropDown() diff --git a/config/cubist.php b/config/cubist.php index 8299bca..7ed9d1b 100644 --- a/config/cubist.php +++ b/config/cubist.php @@ -1,5 +1,7 @@ env('CUBIST_INTERNAL_SEARCH', false), + 'internal_search_index' => env('CUBIST_INTERNAL_SEARCH_INDEX', strtolower(env('APP_NAME', 'App_name') . '_' . env('APP_ENV', 'dev'))), 'page_model' => '\App\Models\Page', 'settings_model' => '\App\Models\Settings', ]; diff --git a/config/elasticsearch.php b/config/elasticsearch.php new file mode 100644 index 0000000..98c1ecd --- /dev/null +++ b/config/elasticsearch.php @@ -0,0 +1,206 @@ + 'default', + + /** + * These are the connection parameters used when building a client. + */ + + 'connections' => [ + + 'default' => [ + + /** + * Hosts + * + * This is an array of hosts that the client will connect to. It can be a + * single host, or an array if you are running a cluster of Elasticsearch + * instances. + * + * This is the only configuration value that is mandatory. + * + * Presently using "extended" host configuration method + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_extended_host_configuration + * + * There is also the shorter "inline" configuration method available + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_inline_host_configuration + */ + + 'hosts' => [ + [ + 'host' => env('ELASTICSEARCH_HOST', '127.0.0.1'), + 'port' => env('ELASTICSEARCH_PORT', 9200), + 'scheme' => env('ELASTICSEARCH_SCHEME', null), + 'user' => env('ELASTICSEARCH_USER', null), + 'pass' => env('ELASTICSEARCH_PASS', null), + + // If you are connecting to an Elasticsearch instance on AWS, you will need these values as well + 'aws' => env('AWS_ELASTICSEARCH_ENABLED', false), + 'aws_region' => env('AWS_REGION', ''), + 'aws_key' => env('AWS_ACCESS_KEY_ID', ''), + 'aws_secret' => env('AWS_SECRET_ACCESS_KEY', '') + ], + ], + + /** + * SSL + * + * If your Elasticsearch instance uses an out-dated or self-signed SSL + * certificate, you will need to pass in the certificate bundle. This can + * either be the path to the certificate file (for self-signed certs), or a + * package like https://github.com/Kdyby/CurlCaBundle. See the documentation + * below for all the details. + * + * If you are using SSL instances, and the certificates are up-to-date and + * signed by a public certificate authority, then you can leave this null and + * just use "https" in the host path(s) above and you should be fine. + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_security.html#_ssl_encryption_2 + */ + + 'sslVerification' => null, + + /** + * Logging + * + * Logging is handled by passing in an instance of Monolog\Logger (which + * coincidentally is what Laravel's default logger is). + * + * If logging is enabled, you either need to set the path and log level + * (some defaults are given for you below), or you can use a custom logger by + * setting 'logObject' to an instance of Psr\Log\LoggerInterface. In fact, + * if you just want to use the default Laravel logger, then set 'logObject' + * to \Log::getMonolog(). + * + * Note: 'logObject' takes precedent over 'logPath'/'logLevel', so set + * 'logObject' null if you just want file-based logging to a custom path. + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#enabling_logger + */ + + 'logging' => false, + + // If you have an existing instance of Monolog you can use it here. + // 'logObject' => \Log::getMonolog(), + + 'logPath' => storage_path('logs/elasticsearch.log'), + + 'logLevel' => Monolog\Logger::INFO, + + /** + * Retries + * + * By default, the client will retry n times, where n = number of nodes in + * your cluster. If you would like to disable retries, or change the number, + * you can do so here. + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_set_retries + */ + + 'retries' => null, + + /** + * The remainder of the configuration options can almost always be left + * as-is unless you have specific reasons to change them. Refer to the + * appropriate sections in the Elasticsearch documentation for what each option + * does and what values it expects. + */ + + /** + * Sniff On Start + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html + */ + + 'sniffOnStart' => false, + + /** + * HTTP Handler + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_configure_the_http_handler + * @see http://ringphp.readthedocs.org/en/latest/client_handlers.html + */ + + 'httpHandler' => null, + + /** + * Connection Pool + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_connection_pool + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_connection_pool.html + */ + + 'connectionPool' => null, + + /** + * Connection Selector + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_connection_selector + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_selectors.html + */ + + 'connectionSelector' => null, + + /** + * Serializer + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_the_serializer + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_serializers.html + */ + + 'serializer' => null, + + /** + * Connection Factory + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_a_custom_connectionfactory + */ + + 'connectionFactory' => null, + + /** + * Endpoint + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/6.0/_configuration.html#_set_the_endpoint_closure + */ + + 'endpoint' => null, + + + /** + * Register additional namespaces + * + * An array of additional namespaces to register. + * + * @example 'namespaces' => [XPack::Security(), XPack::Watcher()] + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/ElasticsearchPHP_Endpoints.html#Elasticsearch_ClientBuilderregisterNamespace_registerNamespace + */ + 'namespaces' => [], + + /** + * Tracer + * + * Tracer is handled by passing in a name of the class implements Psr\Log\LoggerInterface. + * + * @see https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_configuration.html#_setting_a_custom_connectionfactory + */ + 'tracer' => null, + + ], + + ], + +]; -- 2.39.5