Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added index-builder #211

Merged
merged 2 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Builder/ArticleIndexBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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)
{
$name = $manager->getName();
if (!$manager->indexExists()) {
$this->output->writeln(sprintf('Create index for "<comment>%s</comment>" manager.', $name));
$manager->createIndex();

return;
}

if (!$destroy) {
return;
}

$this->output->writeln(sprintf('Drop and create index for "<comment>%s</comment>" manager.', $name));
$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>