From: Vincent Vanwaelscappel Date: Mon, 19 Aug 2019 10:48:31 +0000 (+0200) Subject: wip #2941 0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c13aec32f3aa6ba2c2c866a01cfb090e73c1ec6e;p=cubist_cms-back.git wip #2941 0.5 --- diff --git a/src/CubistBackpackServiceProvider.php b/src/CubistBackpackServiceProvider.php index 7269d76..b55da23 100644 --- a/src/CubistBackpackServiceProvider.php +++ b/src/CubistBackpackServiceProvider.php @@ -2,6 +2,7 @@ namespace Cubist\Backpack; +use Composer\Command\SearchCommand; use Cubist\Backpack\app\Console\Command\MigrateCommand; use Cubist\Backpack\app\Console\Commands\GenerateCommand; use Cubist\Backpack\app\Console\Commands\InstallCommand; @@ -49,6 +50,6 @@ class CubistBackpackServiceProvider extends ServiceProvider */ public function register() { - $this->commands([InstallCommand::class, GenerateCommand::class, MigrateCommand::class]); + $this->commands([InstallCommand::class, GenerateCommand::class, MigrateCommand::class, SearchIndexCommand::class]); } } diff --git a/src/app/Console/Commands/SearchIndex.php b/src/app/Console/Commands/SearchIndex.php deleted file mode 100644 index 2566f93..0000000 --- a/src/app/Console/Commands/SearchIndex.php +++ /dev/null @@ -1,63 +0,0 @@ -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/Console/Commands/SearchIndexCommand.php b/src/app/Console/Commands/SearchIndexCommand.php new file mode 100644 index 0000000..cecef08 --- /dev/null +++ b/src/app/Console/Commands/SearchIndexCommand.php @@ -0,0 +1,63 @@ +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); + } + } +}