From: Vincent Vanwaelscappel Date: Mon, 19 Aug 2019 10:09:00 +0000 (+0200) Subject: wip #2941 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9acc122b2df2ed40860068ba77c135ed9a40b93c;p=cubist_cms-back.git wip #2941 @3 --- diff --git a/composer.json b/composer.json index cb21e49..93d3620 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/app/Console/Commands/SearchIndex.php b/src/app/Console/Commands/SearchIndex.php index c76f5a2..2566f93 100644 --- a/src/app/Console/Commands/SearchIndex.php +++ b/src/app/Console/Commands/SearchIndex.php @@ -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); + } } } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index ccbc3c2..9fdb24a 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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 */ diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index 1e387d6..8b8097b 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -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 = []; diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index e631923..700e24f 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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();