]> _ Git - cubist_cms-back.git/commitdiff
wip #2941 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 19 Aug 2019 10:09:00 +0000 (12:09 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 19 Aug 2019 10:09:00 +0000 (12:09 +0200)
composer.json
src/app/Console/Commands/SearchIndex.php
src/app/Magic/Fields/Field.php
src/app/Magic/Menu/Item.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index cb21e4915c630f3d2db6da7609f479ca067383ec..93d3620fac8eb900215401ee6213831929ef061a 100644 (file)
@@ -21,6 +21,8 @@
     ],
     "require": {
         "php": ">=7.1.3",
+        "ext-dom": "*",
+        "ext-libxml": "*",
         "backpack/crud": "^3.6",
         "backpack/backupmanager": "^1.4",
         "backpack/logmanager": "^2.3",
@@ -40,6 +42,7 @@
         "barryvdh/laravel-debugbar": "^3.2",
         "league/commonmark-ext-autolink": "^1.0",
         "cviebrock/laravel-elasticsearch": "^3.6"
+
     },
     "require-dev": {
         "filp/whoops": "^2.3",
index c76f5a2ebbb353c7cb70dcb8001ad44ba3aafb27..2566f93829d3301a27525d63574e21985ee9a3f0 100644 (file)
@@ -3,6 +3,13 @@
 
 namespace Cubist\Backpack\app\Console\Commands;
 
+use Cubist\Backpack\app\Magic\Menu\Menu;
+use Cubist\Backpack\app\Magic\Menu\PageItem;
+use Cubist\Backpack\app\Magic\Menu\VirtualItem;
+use Cubist\Backpack\app\Template\Navigation;
+use Cubist\Backpack\app\Template\Redirection;
+use Cviebrock\LaravelElasticsearch\Facade;
+use DOMDocument;
 use Illuminate\Console\Command;
 
 
@@ -13,6 +20,44 @@ class SearchIndex extends Command
 
     public function handle()
     {
+        Facade::
+        /** @var Cubist\Backpack\app\Magic\Menu\Item[] $pages */
+        $pages = Menu::getNavigation()->findAll();
 
+        foreach ($pages as $page) {
+            // Skip nav items
+            if ($page instanceof VirtualItem) {
+                continue;
+            }
+            // Skip redirection & navigation pages
+            if ($page instanceof PageItem) {
+                /** @var PageItem $template */
+                $template = $page->getPage()->getUsedTemplate();
+                if ($template instanceof Redirection || $template instanceof Navigation) {
+                    continue;
+                }
+            }
+
+            libxml_use_internal_errors(true);
+            $doc = new DOMDocument();
+            $doc->loadHTMLFile($page->getHref());
+
+            $title = $doc->getElementsByTagName('title');
+            $body = $doc->getElementsByTagName('body');
+
+            $data = [
+                'body' => [
+                    'title' => $title->item(0)->nodeValue,
+                    'body' => $body->item(0)->nodeValue,
+                ],
+                'index' => env('ELASTICSEARCH_INDEX_NAME', 'cubist_elastic_default'),
+                'type' => 'cmspage',
+                'id' => $page->getHref(),
+            ];
+
+            print_r($data);
+
+            Elasticsearch::index($data);
+        }
     }
 }
index ccbc3c2351d3db1fa07e1396ff51d8e7d8ef370b..9fdb24ab0d4165d5a956a0b03511a4d8ec292a2c 100644 (file)
@@ -28,10 +28,6 @@ class Field implements \ArrayAccess
     protected $_cast = false;
     protected $_translatable = false;
 
-    protected $_elastic = false;
-    protected $_elasticType = 'string';
-    protected $_elasticAnalyser = 'standard';
-
     /**
      * @var CubistMagicAbstractModel
      */
@@ -102,7 +98,6 @@ class Field implements \ArrayAccess
         return ['type' => $this->_adminType, 'view_namespace' => $this->_viewNamespace, 'column' => false, 'form' => 'both', 'rules' => '',
             'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable,
             'column_type' => $this->_columnType, 'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
-            'elastic' => $this->_elastic, 'elastic_type' => $this->_elasticType, 'elastic_analyser' => $this->_elasticAnalyser,
             'allow_null' => true,
             'fake' => false, 'store_in' => 'extras', 'attributes' => []];
     }
@@ -187,19 +182,6 @@ class Field implements \ArrayAccess
         }
     }
 
-    public function getElasticMapping()
-    {
-        if (!$this->getAttribute('elastic', false)) {
-            return [];
-        }
-        return [$this->getAttribute('name') =>
-            [
-                'type' => $this->getAttribute('elastic_type'),
-                'analyser' => $this->getAttribute('elastic_analyser')
-            ]
-        ];
-    }
-
     /**
      * @return null|string
      */
index 1e387d639a84b043b3e078dd8a174cbcc03c3b5e..8b8097b3e02e0b5da77e88b16370f4edd8d3e93c 100644 (file)
@@ -158,6 +158,17 @@ class Item
         return $this->findOneBy('href', $href);
     }
 
+    public function findAll()
+    {
+        $res = [$this];
+
+        foreach ($this->getChildren() as $child) {
+            $res = array_merge($res, $child->findAll());
+        }
+
+        return $res;
+    }
+
     public function findAllBy($param, $search)
     {
         $res = [];
index e631923b40572d632f322afff3d21cadc3f24175..700e24fa1d70e73c7f33902d1ddd80147138f63d 100644 (file)
@@ -21,7 +21,6 @@ use Spatie\MediaLibrary\HasMedia\HasMedia;
 use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
 use Spatie\MediaLibrary\Models\Media;
 use Venturecraft\Revisionable\RevisionableTrait;
-use Elasticquent\ElasticquentTrait;
 
 class CubistMagicAbstractModel extends Model implements HasMedia
 {
@@ -37,7 +36,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     use BunchOfFields {
         addField as protected bunchAddField;
     }
-    use ElasticquentTrait;
 
     protected static $_doctrineTypesMapping = ['int' => 'integer'];
 
@@ -77,17 +75,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
      */
     protected $varSetBeforeOperations = [];
 
-    /**
-     * @var array
-     */
-    protected $mappingProperties = [];
-
     public static function boot()
     {
         parent::boot();
     }
 
-
     public function __construct(array $attributes = [])
     {
         $this->setFields();