From ea9310440346f61a4561b367c25a646bc4841b28 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Tue, 27 Jun 2017 16:53:59 +0200 Subject: [PATCH 1/2] added index-builder --- Builder/ArticleIndexBuilder.php | 71 ++++++++++++++++++++ DependencyInjection/SuluArticleExtension.php | 25 +++++++ Resources/config/services.xml | 4 ++ 3 files changed, 100 insertions(+) create mode 100644 Builder/ArticleIndexBuilder.php diff --git a/Builder/ArticleIndexBuilder.php b/Builder/ArticleIndexBuilder.php new file mode 100644 index 000000000..cf9b912aa --- /dev/null +++ b/Builder/ArticleIndexBuilder.php @@ -0,0 +1,71 @@ +buildForManager($this->container->get('es.manager.live'), $this->input->getOption('destroy')); + $this->buildForManager($this->container->get('es.manager.default'), $this->input->getOption('destroy')); + } + + /** + * Build index for given manager. + * + * If index not exists - it will be created. + * If index exists and destroy flag is true - drop and create index. + * Else do nothing. + * + * @param Manager $manager + * @param bool $destroy + */ + private function buildForManager(Manager $manager, $destroy) + { + if (!$manager->indexExists()) { + $manager->createIndex(); + + return; + } + + if (!$destroy) { + return; + } + + $manager->dropAndCreateIndex(); + } +} diff --git a/DependencyInjection/SuluArticleExtension.php b/DependencyInjection/SuluArticleExtension.php index 80ab70bcd..4200076d7 100644 --- a/DependencyInjection/SuluArticleExtension.php +++ b/DependencyInjection/SuluArticleExtension.php @@ -124,6 +124,31 @@ public function prepend(ContainerBuilder $container) ] ); } + + if ($container->hasExtension('massive_build')) { + $container->prependExtensionConfig( + 'massive_build', + [ + 'targets' => [ + 'prod' => [ + 'dependencies' => [ + 'article_index' => [], + ], + ], + 'dev' => [ + 'dependencies' => [ + 'article_index' => [], + ], + ], + 'maintain' => [ + 'dependencies' => [ + 'article_index' => [], + ], + ], + ], + ] + ); + } } /** diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 26189448a..0902023c3 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -327,5 +327,9 @@ + + + + From 20cc36c42a6c615aff716220621aadcfd8f41b9f Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Thu, 29 Jun 2017 08:46:27 +0200 Subject: [PATCH 2/2] added output --- Builder/ArticleIndexBuilder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Builder/ArticleIndexBuilder.php b/Builder/ArticleIndexBuilder.php index cf9b912aa..129134dbb 100644 --- a/Builder/ArticleIndexBuilder.php +++ b/Builder/ArticleIndexBuilder.php @@ -56,7 +56,9 @@ public function build() */ private function buildForManager(Manager $manager, $destroy) { + $name = $manager->getName(); if (!$manager->indexExists()) { + $this->output->writeln(sprintf('Create index for "%s" manager.', $name)); $manager->createIndex(); return; @@ -66,6 +68,7 @@ private function buildForManager(Manager $manager, $destroy) return; } + $this->output->writeln(sprintf('Drop and create index for "%s" manager.', $name)); $manager->dropAndCreateIndex(); } }