|
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
|
|
|
)->addOption( |
|
52
|
|
|
'split', |
|
53
|
|
|
null, |
|
54
|
|
|
InputOption::VALUE_REQUIRED, |
|
55
|
|
|
'Split file in a separate parts if line number exceeds provided value', |
|
56
|
|
|
300000 |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
64
|
|
|
{ |
|
65
|
|
|
$io = new SymfonyStyle($input, $output); |
|
66
|
|
|
$manager = $this->getManager($input->getOption('manager')); |
|
67
|
|
|
|
|
68
|
|
|
/** @var ExportService $exportService */ |
|
69
|
|
|
$exportService = $this->getContainer()->get('es.export'); |
|
70
|
|
|
$exportService->exportIndex( |
|
71
|
|
|
$manager, |
|
72
|
|
|
$input->getArgument('filename'), |
|
73
|
|
|
$input->getOption('types'), |
|
74
|
|
|
$input->getOption('chunk'), |
|
75
|
|
|
$output, |
|
76
|
|
|
$input->getOption('split') |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$io->success('Data export completed!'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|