Completed
Pull Request — develop (#211)
by Wachter
15:13
created

ArticleIndexBuilder::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ArticleBundle\Builder;
13
14
use ONGR\ElasticsearchBundle\Service\Manager;
15
use Sulu\Bundle\CoreBundle\Build\SuluBuilder;
16
17
/**
18
 * Builder for article-index.
19
 */
20
class ArticleIndexBuilder extends SuluBuilder
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getName()
26
    {
27
        return 'article_index';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getDependencies()
34
    {
35
        return ['cache'];
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function build()
42
    {
43
        $this->buildForManager($this->container->get('es.manager.live'), $this->input->getOption('destroy'));
44
        $this->buildForManager($this->container->get('es.manager.default'), $this->input->getOption('destroy'));
45
    }
46
47
    /**
48
     * Build index for given manager.
49
     *
50
     * If index not exists - it will be created.
51
     * If index exists and destroy flag is true - drop and create index.
52
     * Else do nothing.
53
     *
54
     * @param Manager $manager
55
     * @param bool $destroy
56
     */
57
    private function buildForManager(Manager $manager, $destroy)
58
    {
59
        if (!$manager->indexExists()) {
60
            $manager->createIndex();
61
62
            return;
63
        }
64
65
        if (!$destroy) {
66
            return;
67
        }
68
69
        $manager->dropAndCreateIndex();
70
    }
71
}
72