1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GBProd\ElasticaExtraBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Command to remove alias |
12
|
|
|
* |
13
|
|
|
* @author gbprod <[email protected]> |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class RemoveAliasCommand extends ElasticaAwareCommand |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
1 |
|
protected function configure() |
21
|
|
|
{ |
22
|
1 |
|
$this |
23
|
1 |
|
->setName('elasticsearch:alias:remove') |
24
|
1 |
|
->setDescription('Remove alias to an index') |
25
|
1 |
|
->addArgument('index', InputArgument::REQUIRED, 'Which index ?') |
26
|
1 |
|
->addArgument('alias', InputArgument::REQUIRED, 'Alias name') |
27
|
1 |
|
->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null) |
28
|
|
|
; |
29
|
1 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
35
|
|
|
{ |
36
|
1 |
|
$client = $this->getClient($input->getOption('client')); |
37
|
1 |
|
$index = $input->getArgument('index'); |
38
|
1 |
|
$alias = $input->getArgument('alias'); |
39
|
|
|
|
40
|
1 |
|
$output->writeln(sprintf( |
41
|
1 |
|
'<info>Remove alias <comment>%s</comment> for index <comment>%s</comment></info>', |
42
|
1 |
|
$alias, |
43
|
|
|
$index |
44
|
1 |
|
)); |
45
|
|
|
|
46
|
1 |
|
$this |
47
|
1 |
|
->getContainer() |
48
|
1 |
|
->get('gbprod.elastica_extra.remove_alias_handler') |
49
|
1 |
|
->handle($client, $index, $alias); |
50
|
|
|
; |
51
|
|
|
|
52
|
1 |
|
$output->writeln('done'); |
53
|
1 |
|
} |
54
|
|
|
} |
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.