Completed
Push — 1.0 ( f45751...770e00 )
by Simonas
12:41 queued 10:12
created

IndexImportCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 23
rs 9.0856
cc 2
eloc 14
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Command;
13
14
use ONGR\ElasticsearchBundle\Service\ImportService;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Style\SymfonyStyle;
20
21
/**
22
 * IndexImportCommand class.
23
 */
24
class IndexImportCommand extends AbstractManagerAwareCommand
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function configure()
30
    {
31
        parent::configure();
32
33
        $this
34
            ->setName('ongr:es:index:import')
35
            ->setDescription('Imports data to elasticsearch index.')
36
            ->addArgument(
37
                'filename',
38
                InputArgument::REQUIRED,
39
                'Select file to store output'
40
            )
41
            ->addOption(
42
                'bulk-size',
43
                'b',
44
                InputOption::VALUE_REQUIRED,
45
                'Set bulk size for import',
46
                1000
47
            )
48
            ->addOption(
49
                'gzip',
50
                'z',
51
                InputOption::VALUE_NONE,
52
                'Import a gzip file'
53
            );
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61
        $io = new SymfonyStyle($input, $output);
62
        $manager = $this->getManager($input->getOption('manager'));
63
64
        // Initialize options array
65
        $options = [];
66
        if ($input->getOption('gzip')) {
67
            $options['gzip'] = null;
68
        }
69
        $options['bulk-size'] = $input->getOption('bulk-size');
70
71
        /** @var ImportService $importService */
72
        $importService = $this->getContainer()->get('es.import');
73
        $importService->importIndex(
74
            $manager,
75
            $input->getArgument('filename'),
76
            $output,
77
            $options
78
        );
79
80
        $io->success('Data import completed!');
81
    }
82
}
83