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 put index mappings |
12
|
|
|
* |
13
|
|
|
* @author gbprod <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class PutIndexMappingsCommand extends ElasticaAwareCommand |
16
|
|
|
{ |
17
|
2 |
View Code Duplication |
protected function configure() |
|
|
|
|
18
|
|
|
{ |
19
|
2 |
|
$this |
20
|
2 |
|
->setName('elasticsearch:index:put_mappings') |
21
|
2 |
|
->setDescription('Put index mappings from configuration') |
22
|
2 |
|
->addArgument('index', InputArgument::REQUIRED, 'Which index ?') |
23
|
2 |
|
->addArgument('type', InputArgument::REQUIRED, 'Which type ?') |
24
|
2 |
|
->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null) |
25
|
2 |
|
->addOption('alias', null, InputOption::VALUE_REQUIRED, 'Index configuration to use (if not the same as index argument)', null) |
|
|
|
|
26
|
|
|
; |
27
|
2 |
|
} |
28
|
|
|
|
29
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
2 |
|
$client = $this->getClient($input->getOption('client')); |
32
|
2 |
|
$index = $input->getArgument('index'); |
33
|
2 |
|
$type = $input->getArgument('type'); |
34
|
2 |
|
$alias = $input->getOption('alias') ?: $index; |
35
|
|
|
|
36
|
2 |
|
$output->writeln(sprintf( |
37
|
|
|
'<info>Put type <comment>%s</comment> mappings for index <comment>%s</comment> '. |
38
|
2 |
|
'client <comment>%s</comment>...</info>', |
39
|
2 |
|
$type, |
40
|
2 |
|
$index, |
41
|
2 |
|
$input->getOption('client') |
42
|
2 |
|
)); |
43
|
|
|
|
44
|
2 |
|
$handler = $this |
45
|
2 |
|
->getContainer() |
46
|
2 |
|
->get('gbprod.elastica_extra.put_index_mappings_handler') |
47
|
2 |
|
; |
48
|
|
|
|
49
|
2 |
|
$handler->handle($client, $index, $type, $alias); |
50
|
|
|
|
51
|
2 |
|
$output->writeln('done'); |
52
|
2 |
|
} |
53
|
|
|
} |
54
|
|
|
|
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.