1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OldSound\RabbitMqBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Command to purge a queue |
13
|
|
|
*/ |
14
|
|
|
class PurgeConsumerCommand extends ConsumerCommand |
15
|
|
|
{ |
16
|
1 |
|
protected function configure() |
17
|
|
|
{ |
18
|
1 |
|
$this->addArgument('name', InputArgument::REQUIRED, 'Consumer Name') |
19
|
1 |
|
->setDescription('Purge a consumer\'s queue') |
20
|
1 |
|
->addOption('no-confirmation', null, InputOption::VALUE_NONE, 'Whether it must be confirmed before purging'); |
21
|
|
|
|
22
|
1 |
|
$this->setName('rabbitmq:purge'); |
23
|
1 |
|
} |
24
|
|
|
|
25
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
26
|
|
|
{ |
27
|
|
|
// nothing to initialize here as BaseConsumerCommand initializes on option that is not available here |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param InputInterface $input |
32
|
|
|
* @param OutputInterface $output |
33
|
|
|
* |
34
|
|
|
* @return int |
35
|
|
|
*/ |
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$noConfirmation = (bool) $input->getOption('no-confirmation'); |
39
|
|
|
|
40
|
|
|
if (!$noConfirmation && $input->isInteractive()) { |
41
|
|
|
$question = new ConfirmationQuestion( |
42
|
|
|
sprintf( |
43
|
|
|
'<question>Are you sure you wish to purge "%s" queue? (y/n)</question>', |
44
|
|
|
$input->getArgument('name') |
|
|
|
|
45
|
|
|
), |
46
|
|
|
false |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
if (!$this->getHelper('question')->ask($input, $output, $question)) { |
50
|
|
|
$output->writeln('<error>Purging cancelled!</error>'); |
51
|
|
|
|
52
|
|
|
return 1; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->consumer = $this->getContainer() |
57
|
|
|
->get(sprintf($this->getConsumerService(), $input->getArgument('name'))); |
58
|
|
|
$this->consumer->purge($input->getArgument('name')); |
|
|
|
|
59
|
|
|
|
60
|
|
|
return 0; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|