Skip to content

Commit

Permalink
added index-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Jun 27, 2017
1 parent 45290a1 commit 77dc51f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Builder/ArticleIndexBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Builder;

use ONGR\ElasticsearchBundle\Service\Manager;
use Sulu\Bundle\CoreBundle\Build\SuluBuilder;

/**
* Builder for article-index
*/
class ArticleIndexBuilder extends SuluBuilder
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'article_index';
}

/**
* {@inheritdoc}
*/
public function getDependencies()
{
return ['cache'];
}

/**
* {@inheritdoc}
*/
public function build()
{
$this->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();
}
}
25 changes: 25 additions & 0 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
],
],
],
]
);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,9 @@

<tag name="twig.extension"/>
</service>

<service id="sulu_article.builder.index" class="Sulu\Bundle\ArticleBundle\Builder\ArticleIndexBuilder">
<tag name="massive_build.builder" />
</service>
</services>
</container>

0 comments on commit 77dc51f

Please sign in to comment.