|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
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 FOS\ElasticaBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use FOS\ElasticaBundle\Index\TemplateResetter; |
|
15
|
|
|
use Symfony\Component\Console\Command\Command; |
|
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\Question\ConfirmationQuestion; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Reset search indexes templates. |
|
23
|
|
|
*/ |
|
24
|
|
|
final class ResetTemplatesCommand extends Command |
|
25
|
|
|
{ |
|
26
|
|
|
protected static $defaultName = 'fos:elastica:reset-templates'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Resetter |
|
30
|
|
|
* |
|
31
|
|
|
* @var TemplateResetter |
|
32
|
|
|
*/ |
|
33
|
|
|
private $resetter; |
|
34
|
|
|
|
|
35
|
4 |
|
public function __construct( |
|
36
|
|
|
TemplateResetter $resetter |
|
37
|
|
|
) { |
|
38
|
4 |
|
parent::__construct(); |
|
39
|
|
|
|
|
40
|
4 |
|
$this->resetter = $resetter; |
|
41
|
4 |
|
} |
|
42
|
|
|
|
|
43
|
4 |
|
protected function configure() |
|
44
|
|
|
{ |
|
45
|
|
|
$this |
|
46
|
4 |
|
->setName('fos:elastica:reset-templates') |
|
47
|
4 |
|
->addOption( |
|
48
|
4 |
|
'index', |
|
49
|
4 |
|
null, |
|
50
|
4 |
|
InputOption::VALUE_OPTIONAL, |
|
51
|
4 |
|
'The index template to reset. If no index template name specified than all templates will be reset', |
|
52
|
4 |
|
true |
|
53
|
|
|
) |
|
54
|
4 |
|
->addOption( |
|
55
|
4 |
|
'force-delete', |
|
56
|
4 |
|
null, |
|
57
|
4 |
|
InputOption::VALUE_NONE, |
|
58
|
|
|
'Delete all indexes that matches index templates patterns. ' . |
|
59
|
4 |
|
'Aware that pattern may match various indexes.' |
|
60
|
|
|
) |
|
61
|
4 |
|
->setDescription('Reset search indexes templates') |
|
62
|
|
|
; |
|
63
|
4 |
|
} |
|
64
|
|
|
|
|
65
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
66
|
|
|
{ |
|
67
|
4 |
|
$indexTemplate = $input->hasParameterOption('--index') ? $input->getOption('index') : null; |
|
68
|
4 |
|
$deleteByPattern = (bool) $input->getOption('force-delete'); |
|
69
|
|
|
|
|
70
|
4 |
|
if ($deleteByPattern) { |
|
71
|
2 |
|
$helper = $this->getHelper('question'); |
|
72
|
2 |
|
$question = new ConfirmationQuestion('You are going to remove all template indexes. Are you sure?', false); |
|
73
|
2 |
|
if (!$helper->ask($input, $output, $question)) { |
|
74
|
|
|
return; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
4 |
|
if (is_string($indexTemplate)) { |
|
79
|
2 |
|
$output->writeln(sprintf('<info>Resetting template</info> <comment>%s</comment>', $indexTemplate)); |
|
80
|
2 |
|
$this->resetter->resetIndex($indexTemplate, $deleteByPattern); |
|
81
|
|
|
} else { |
|
82
|
2 |
|
$output->writeln('<info>Resetting all templates</info>'); |
|
83
|
2 |
|
$this->resetter->resetAllIndexes($deleteByPattern); |
|
84
|
|
|
} |
|
85
|
4 |
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|