Completed
Push — master ( 14a1e9...0416c5 )
by GBProd
03:35
created

PutIndexMappingsCommand::execute()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 18
cts 18
cp 1
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 2
crap 2
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)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 140 characters

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.

Loading history...
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