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
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* IndexExportCommand class. |
22
|
|
|
*/ |
23
|
|
|
class IndexExportCommand extends AbstractManagerAwareCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
parent::configure(); |
31
|
|
|
|
32
|
|
|
$this |
33
|
|
|
->setName('ongr:es:index:export') |
34
|
|
|
->setDescription('Exports data from elasticsearch index.') |
35
|
|
|
->addArgument( |
36
|
|
|
'filename', |
37
|
|
|
InputArgument::REQUIRED, |
38
|
|
|
'Select file to store output' |
39
|
|
|
)->addOption( |
40
|
|
|
'chunk', |
41
|
|
|
null, |
42
|
|
|
InputOption::VALUE_REQUIRED, |
43
|
|
|
'Chunk size to use in scan api', |
44
|
|
|
500 |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$manager = $this->getManager($input->getOption('manager')); |
54
|
|
|
|
55
|
|
|
/** @var ExportService $exportService */ |
56
|
|
|
$exportService = $this->getContainer()->get('es.export'); |
57
|
|
|
$exportService->exportIndex($manager, $input->getArgument('filename'), $input->getOption('chunk'), $output); |
58
|
|
|
|
59
|
|
|
$output->writeln('<info>Data export completed!</info>'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.