Completed
Push — v0.10 ( f42b97...309689 )
by Simonas
8s
created

IndexDropCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 9.2
cc 2
eloc 13
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Command for dropping Elasticsearch index.
20
 */
21
class IndexDropCommand extends AbstractManagerAwareCommand
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function configure()
27
    {
28
        parent::configure();
29
30
        $this
31
            ->setName('ongr:es:index:drop')
32
            ->setDescription('Drops elasticsearch index.')
33
            ->addOption(
34
                'force',
35
                'f',
36
                InputOption::VALUE_NONE,
37
                'Set this parameter to execute this command'
38
            );
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        if ($input->getOption('force')) {
47
            $this->getManager($input->getOption('manager'))->getConnection()->dropIndex();
48
49
            $output->writeln(
50
                sprintf(
51
                    '<info>Dropped index for manager named</info> <comment>`%s`</comment>',
52
                    $input->getOption('manager')
53
                )
54
            );
55
        } else {
56
            $output->writeln(
57
                '<error>ATTENTION:</error> This action should not be used in production environment.'
58
                . "\n\nOption --force has to be used to drop type(s)."
59
            );
60
61
            return 1;
62
        }
63
64
        return 0;
65
    }
66
}
67