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