]> _ Git - cubist_cms-back.git/commitdiff
wip #2941 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 20 Aug 2019 16:28:49 +0000 (18:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 20 Aug 2019 16:28:49 +0000 (18:28 +0200)
src/app/Console/Commands/SearchIndexCommand.php
src/app/Magic/Models/CubistMagicPageModel.php
src/app/Magic/Models/News.php
src/app/Magic/PageData.php
src/resources/config/cubist.php

index b76904860605527294e748d490d8db44ae822910..a049e3a2747956c7ce31ec9dde41cc2b60c2cf6d 100644 (file)
@@ -20,14 +20,14 @@ class SearchIndexCommand extends Command
 
     public function handle()
     {
-        $index = env('ELASTICSEARCH_INDEX_NAME', 'cubist_elastic_default_1');
-        echo env('ELASTICSEARCH_HOST');
+        $index = config('cubist.internal_search_index');
 
         try {
             Elasticsearch::indices()->delete(['index' => $index]);
         } catch (\Exception $e) {
             echo $e->getMessage();
         }
+
         Elasticsearch::indices()->create(
             [
                 'index' => $index,
@@ -71,7 +71,7 @@ class SearchIndexCommand extends Command
             $doc = new DOMSelector($html);
 
             /** @var \DOMElement $meta */
-            $meta = $doc->select('meta[data-search]')[0];
+            $meta = $doc->select('meta[data-search]', false)[0];
             $enabled = $meta->getAttribute('data-search') == '1';
             if (!$enabled) {
                 continue;
@@ -80,10 +80,11 @@ class SearchIndexCommand extends Command
             $keywords = $meta->getAttribute('data-keywords');
 
             $body = [
-                'long_title' => (string)$doc->select('title')[0],
                 'short_title' => $short_title,
+                'long_title' => (string)$doc->select('title')[0]['text'],
                 'keywords' => $keywords,
-                'main' => $doc->getDOM()->saveHTML($doc->select('main')->item(0)),
+                'description' => $doc->select('meta[name="description"]')[0]['attributes']['content'],
+                'main' => $doc->getDOM()->saveHTML($doc->select('main', false)->item(0)),
             ];
 
             $data = [
index 1c9fbf49db7f30540e7a6c3dfa85a757a7b977d8..ca5ebdbc0d01bed8e907da3d502e6cd7e889d7c6 100644 (file)
@@ -23,13 +23,18 @@ class CubistMagicPageModel extends CubistMagicModel
             'label' => 'Activer',
             'default' => true,
             'hint' => 'Référencer cette page dans le moteur de recherche interne',
-            'tab' => $tab]);
+            'tab' => $tab,
+            'fake' => true,
+            'store_in' => 'search_internal']);
 
         $this->addField(['name' => 'search_internal_keywords',
             'type' => 'Tags',
             'label' => 'Mots clés',
             'hint' => 'Mots supplémentaires à utiliser par le moteur de recherche',
-            'tab' => $tab]);
+            'tab' => $tab,
+            'translatable' => true,
+            'fake' => true,
+            'store_in' => 'search_internal']);
     }
 
     protected function _seo()
@@ -48,6 +53,7 @@ class CubistMagicPageModel extends CubistMagicModel
             'type' => 'Text',
             'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'),
             'tab' => $tab,
+            'fake' => true,
             'store_in' => 'seo',
         ]);
 
@@ -57,6 +63,7 @@ class CubistMagicPageModel extends CubistMagicModel
             'type' => 'Textarea',
             'hint' => __('Recommended length: 160 chars'),
             'tab' => $tab,
+            'fake' => true,
             'store_in' => 'seo',
         ]);
 
@@ -66,6 +73,7 @@ class CubistMagicPageModel extends CubistMagicModel
             'type' => 'Checkbox',
             'default' => true,
             'tab' => $tab,
+            'fake' => true,
             'store_in' => 'seo',
         ]);
     }
index f2635504c529cea83cbb4d7a7f4fbf41b0367771..9731b5ae3f42747a95bd31418380506da888bfc5 100644 (file)
@@ -15,34 +15,31 @@ class News extends CubistMagicPageModel
 
     public function setFields()
     {
-        parent::setFields();
-
         $this->addField(['name' => 'title',
             'label' => 'Titre',
             'type' => 'Text',
             'column' => true,
-            'elastic' => true,]);
-
-        $this->addField(['name' => 'slug',
-            'type' => 'Slug',
-            'label' => 'Slug (URL)']);
+            'tab'=>'Contenus']);
 
         $this->addField(['name' => 'type',
             'type' => 'SelectFromArray',
             'label' => 'Type',
             'options' => ['news' => 'Actualité', 'event' => 'Evénement'],
             'column' => true,
+            'tab'=>'Contenus'
         ]);
 
         $this->addField(['name' => 'date',
             'type' => 'Datetime',
             'label' => 'Date de publication',
-            'column' => true]);
+            'column' => true,
+            'tab'=>'Contenus']);
 
         $this->addField(['name' => 'event_start',
             'type' => 'Date',
             'label' => 'Début de l\'évenement',
             'when' => ['type' => ['event']],
+            'tab'=>'Contenus'
         ]);
 
         $this->addField(['name' => 'event_end',
@@ -55,7 +52,7 @@ class News extends CubistMagicPageModel
             'type' => 'Text',
             'label' => 'Lieu de l\'événement',
             'when' => ['type' => ['event']],
-            'elastic' => true,
+            'tab'=>'Contenus'
         ]);
 
         $this->addField(['name' => 'chapo',
@@ -63,24 +60,28 @@ class News extends CubistMagicPageModel
             'label' => 'Chapo',
             'hint' => 'Texte court affiché sur le listing des actualités',
             'when' => ['type' => ['news']],
-            'elastic' => true,
+            'tab'=>'Contenus'
         ]);
 
         $this->addField(['name' => 'image',
             'type' => 'Images',
-            'label' => 'Image']);
+            'label' => 'Image',
+            'tab'=>'Contenus']);
 
         $this->addField(['name' => 'content',
             'type' => 'Markdown',
             'label' => 'Contenu',
-            'elastic' => true,
+            'tab'=>'Contenus'
         ]);
 
         $this->addField(['name' => 'status',
             'type' => 'SelectFromArray',
             'label' => 'Status',
             'options' => ['0' => 'Offline', '1' => 'Published'],
-            'column' => true
+            'column' => true,
+            'tab'=>'Contenus'
         ]);
+
+        parent::setFields();
     }
 }
index 584a100153722a49e1dbb999c72c7e6bef310422..55b992312a72d42bd8b43992321d3c6bf0769e88 100644 (file)
@@ -96,32 +96,43 @@ class PageData implements \ArrayAccess
     }
 
     /**
-     * @param string $offset
+     * @param string|array $offset
      * @param mixed $default
      * @return mixed
      */
     public function get($offset, $default = null)
     {
-        $res = Arr::get($this->_data, $offset, $default);
-
-        // If an array value is saved without any items, it might be returned
-        // as a string "[]" when instead it should be an empty array...
-        if ($res === '[]') {
-            $res = [];
+        if (!is_array($offset)) {
+            $offset = [$offset];
         }
 
-        // Get the translated value if the array contains a key matching the locale.
-        // We have to check if the key exists because the actual value may be null.
-        // Using isset() on the locale key would give a false negative if the value is null.
-        if (is_array($res) && array_key_exists(App::getLocale(), $res)) {
-            $res = $res[App::getLocale()];
-        }
+        foreach ($offset as $key) {
+            if (!Arr::has($this->_data, $key)) {
+                continue;
+            }
 
-        if (!$res) {
-            return $default;
-        }
+            $res = Arr::get($this->_data, $key, $default);
 
-        return $res;
+            // If an array value is saved without any items, it might be returned
+            // as a string "[]" when instead it should be an empty array...
+            if ($res === '[]') {
+                $res = [];
+            }
+
+            // Get the translated value if the array contains a key matching the locale.
+            // We have to check if the key exists because the actual value may be null.
+            // Using isset() on the locale key would give a false negative if the value is null.
+            if (is_array($res) && array_key_exists(App::getLocale(), $res)) {
+                $res = $res[App::getLocale()];
+            }
+
+            if (!$res) {
+                return $default;
+            }
+            return $res;
+
+        }
+        return $default;
     }
 
     /**
index ed5255db70f91cc438edb6337db07b1b63cd0669..7ed9d1b23cf0dca88e1bb9093a0f2ed3a6475a90 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 return [
     'internal_search' => 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',
 ];