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 |
|
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('config', 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 |
|
$config = $input->getOption('config') ?: $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, $config); |
50
|
|
|
|
51
|
2 |
|
$output->writeln('done'); |
52
|
2 |
|
} |
53
|
|
|
} |
54
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.