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

IndexExportCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
rs 8.9713
cc 1
eloc 20
nc 1
nop 0
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\ExportService;
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
 * IndexExportCommand class.
23
 */
24
class IndexExportCommand extends AbstractManagerAwareCommand
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function configure()
30
    {
31
        parent::configure();
32
33
        $this
34
            ->setName('ongr:es:index:export')
35
            ->setDescription('Exports data from elasticsearch index.')
36
            ->addArgument(
37
                'filename',
38
                InputArgument::REQUIRED,
39
                'Select file to store output'
40
            )->addOption(
41
                'types',
42
                null,
43
                InputOption::VALUE_REQUIRED + InputOption::VALUE_IS_ARRAY,
44
                'Export specific types only'
45
            )->addOption(
46
                'chunk',
47
                null,
48
                InputOption::VALUE_REQUIRED,
49
                'Chunk size to use in scan api',
50
                500
51
            );
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59
        $io = new SymfonyStyle($input, $output);
60
        $manager = $this->getManager($input->getOption('manager'));
61
62
        /** @var ExportService $exportService */
63
        $exportService = $this->getContainer()->get('es.export');
64
        $exportService->exportIndex(
65
            $manager,
66
            $input->getArgument('filename'),
67
            $input->getOption('types'),
68
            $input->getOption('chunk'),
69
            $output
70
        );
71
72
        $io->success('Data export completed!');
73
    }
74
}
75