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
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* IndexImportCommand class. |
22
|
|
|
*/ |
23
|
|
|
class IndexImportCommand extends AbstractManagerAwareCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
parent::configure(); |
31
|
|
|
|
32
|
|
|
$this |
33
|
|
|
->setName('ongr:es:index:import') |
34
|
|
|
->setDescription('Imports data to elasticsearch index.') |
35
|
|
|
->addArgument( |
36
|
|
|
'filename', |
37
|
|
|
InputArgument::REQUIRED, |
38
|
|
|
'Select file to store output' |
39
|
|
|
) |
40
|
|
|
->addOption( |
41
|
|
|
'bulk-size', |
42
|
|
|
'b', |
43
|
|
|
InputOption::VALUE_REQUIRED, |
44
|
|
|
'Set bulk size for import', |
45
|
|
|
1000 |
46
|
|
|
) |
47
|
|
|
->addOption( |
48
|
|
|
'gzip', |
49
|
|
|
'z', |
50
|
|
|
InputOption::VALUE_NONE, |
51
|
|
|
'Import a gzip file' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
59
|
|
|
{ |
60
|
|
|
$manager = $this->getManager($input->getOption('manager')); |
61
|
|
|
|
62
|
|
|
$options = []; |
63
|
|
|
if ($input->getOption('gzip')) { |
64
|
|
|
$options['gzip'] = true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** @var ImportService $importService */ |
68
|
|
|
$importService = $this->getContainer()->get('es.import'); |
69
|
|
|
$importService->importIndex( |
70
|
|
|
$manager, |
71
|
|
|
$input->getArgument('filename'), |
72
|
|
|
$output, |
73
|
|
|
$input->getOption('bulk-size'), |
74
|
|
|
$options |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$output->writeln('<info>Data import completed!</info>'); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|