Completed
Pull Request — 1.0 (#642)
by
unknown
02:52
created

IndexDropCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 12
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
use Symfony\Component\Console\Style\SymfonyStyle;
18
19
/**
20
 * Command for dropping Elasticsearch index.
21
 */
22
class IndexDropCommand extends AbstractManagerAwareCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
31
        $this
32
            ->setName('ongr:es:index:drop')
33
            ->setDescription('Drops elasticsearch index.')
34
            ->addOption(
35
                'force',
36
                'f',
37
                InputOption::VALUE_NONE,
38
                'Set this parameter to execute this command'
39
            );
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $io = new SymfonyStyle($input, $output);
48
        if ($input->getOption('force')) {
49
            $this->getManager($input->getOption('manager'))->dropIndex();
50
51
            $io->text(
52
                sprintf(
53
                    'Dropped index for the<comment>`%s`</comment> manager',
54
                    $input->getOption('manager')
55
                )
56
            );
57
        } else {
58
            $io->error('ATTENTION:');
59
            $io->text('This action should not be used in the production environment.');
60
            $io->error('Option --force is mandatory to drop type(s).');
61
        }
62
    }
63
}
64