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 Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* This command puts warmers into elasticsearch index. |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class WarmerPutCommand extends AbstractManagerAwareCommand |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
protected function configure() |
27
|
|
|
{ |
28
|
|
|
parent::configure(); |
29
|
|
|
|
30
|
|
|
$this |
31
|
|
|
->setName('ongr:es:warmer:put') |
32
|
|
|
->setDescription('Puts warmers into elasticsearch index.') |
33
|
|
|
->addArgument( |
34
|
|
|
'names', |
35
|
|
|
InputArgument::IS_ARRAY | InputArgument::OPTIONAL, |
36
|
|
|
'Warmers names.', |
37
|
|
|
[] |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
45
|
|
|
{ |
46
|
|
|
$names = $input->getArgument('names'); |
47
|
|
|
$status = $this->getManager($input->getOption('manager'))->getConnection()->putWarmers($names); |
48
|
|
|
|
49
|
|
|
if ($status === false) { |
50
|
|
|
$message = '<info>There are no warmers registered for manager named<info> <comment>`%s`</comment>!'; |
51
|
|
|
} elseif (empty($names)) { |
52
|
|
|
$message = '<info>All warmers have been put into manager named<info> <comment>`%s`</comment>'; |
53
|
|
|
} else { |
54
|
|
|
$callback = function ($val) { |
55
|
|
|
return '`' . $val . '`'; |
56
|
|
|
}; |
57
|
|
|
$message = '<comment>' . implode(', ', array_map($callback, $names)) . '</comment>' |
58
|
|
|
. '<info> warmer(s) have been put into manager named</info> <comment>`%s`</comment>'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$output->writeln(sprintf($message, $input->getOption('manager'))); |
62
|
|
|
|
63
|
|
|
return 0; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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.