|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GBProd\ElasticsearchDataProviderBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Command to run providing |
|
14
|
|
|
* |
|
15
|
|
|
* @author gbprod <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class ProvideCommand extends ContainerAwareCommand |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
1 |
|
protected function configure() |
|
23
|
|
|
{ |
|
24
|
1 |
|
$this |
|
25
|
1 |
|
->setName('elasticsearch:provide') |
|
26
|
1 |
|
->setDescription('Provide data to Elasticsearch') |
|
27
|
1 |
|
->addArgument( |
|
28
|
1 |
|
'index', |
|
29
|
1 |
|
InputArgument::OPTIONAL, |
|
30
|
|
|
'Index to provide' |
|
31
|
1 |
|
) |
|
32
|
1 |
|
->addArgument( |
|
33
|
1 |
|
'type', |
|
34
|
1 |
|
InputArgument::OPTIONAL, |
|
35
|
|
|
'Type to provide' |
|
36
|
1 |
|
) |
|
37
|
1 |
|
->addOption( |
|
38
|
1 |
|
'client', |
|
39
|
1 |
|
null, |
|
40
|
1 |
|
InputOption::VALUE_REQUIRED, |
|
41
|
1 |
|
'Client to use (if not default)', |
|
42
|
|
|
'default' |
|
43
|
1 |
|
) |
|
44
|
|
|
; |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$handler = $this->getContainer() |
|
53
|
1 |
|
->get('gbprod.elasticsearch_dataprovider.handler') |
|
54
|
1 |
|
; |
|
55
|
|
|
|
|
56
|
1 |
|
$client = $this->getClient($input->getOption('client')); |
|
57
|
|
|
|
|
58
|
1 |
|
$index = $input->getArgument('index'); |
|
59
|
1 |
|
$type = $input->getArgument('type'); |
|
60
|
|
|
|
|
61
|
1 |
|
$output->writeln(sprintf( |
|
62
|
1 |
|
'<info>Providing <comment>%s/%s</comment> for client <comment>%s</comment></info>', |
|
63
|
1 |
|
$index ?: '*', |
|
64
|
1 |
|
$type ?: '*', |
|
65
|
1 |
|
$input->getOption('client') |
|
66
|
1 |
|
)); |
|
67
|
|
|
|
|
68
|
1 |
|
$this->initializeProgress($output); |
|
69
|
|
|
|
|
70
|
1 |
|
$handler->handle($client, $index, $type); |
|
71
|
1 |
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
private function getClient($clientName) |
|
74
|
|
|
{ |
|
75
|
1 |
|
$client = $this->getContainer() |
|
76
|
1 |
|
->get(sprintf( |
|
77
|
1 |
|
'm6web_elasticsearch.client.%s', |
|
78
|
|
|
$clientName |
|
79
|
1 |
|
)) |
|
80
|
1 |
|
; |
|
81
|
|
|
|
|
82
|
1 |
|
if (!$client) { |
|
83
|
|
|
throw new \InvalidArgumentException(sprintf( |
|
84
|
|
|
'No client "%s" found', |
|
85
|
|
|
$clientName |
|
86
|
|
|
)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
1 |
|
return $client; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
private function initializeProgress(OutputInterface $output) |
|
93
|
|
|
{ |
|
94
|
1 |
|
$dispatcher = $this->getContainer()->get('event_dispatcher'); |
|
95
|
|
|
|
|
96
|
1 |
|
new ProvidingProgressBar($dispatcher, $output); |
|
97
|
1 |
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|