1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Solr\Console\Command\Collection; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\ClientException; |
6
|
|
|
use GuzzleHttp\Exception\ConnectException; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument as IArg; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Reload collection. |
13
|
|
|
*/ |
14
|
|
|
class Reload extends Command |
15
|
|
|
{ |
16
|
|
|
protected function configure() |
17
|
|
|
{ |
18
|
|
|
$this->setName('collection:reload') |
19
|
|
|
->setDescription('Used when you have changed a configuration in ZooKeeper.'); |
20
|
|
|
|
21
|
|
|
$this->addArgument('name', IArg::REQUIRED, 'Collection name'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Execute reload command. Reload collection. |
26
|
|
|
* |
27
|
|
|
* @param Symfony\Component\Console\Input\InputInterface $input |
28
|
|
|
* @param Symfony\Component\Console\Output\OutpuInterface $output |
29
|
|
|
* |
30
|
|
|
* @return int |
31
|
|
|
*/ |
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
33
|
|
|
{ |
34
|
|
|
try { |
35
|
|
|
$name = $input->getArgument('name'); |
36
|
|
|
$result = $this->client |
37
|
|
|
->get("admin/collections?action=RELOAD&name={$name}&wt=json") |
38
|
|
|
->json(); |
39
|
|
|
|
40
|
|
|
if (isset($result['success'])) { |
41
|
|
|
$output->writeln('<fg=green>The collection was reloaded</fg=green>'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return 0; |
45
|
|
|
} catch (ClientException $e) { |
46
|
|
|
$response = $e->getResponse()->json(); |
47
|
|
|
|
48
|
|
|
if (isset($response['error']['msg'])) { |
49
|
|
|
$output->writeln("<fg=red>{$response['error']['msg']}</fg=red>"); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return 1; |
53
|
|
|
} catch (ConnectException $e) { |
54
|
|
|
$output->writeln('<fg=red>The connection failed for host</fg=red>'); |
55
|
|
|
|
56
|
|
|
return 1; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|