|
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 delete a queue |
|
13
|
|
|
*/ |
|
14
|
|
|
class DeleteCommand extends ConsumerCommand |
|
15
|
|
|
{ |
|
16
|
|
|
protected function configure() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->addArgument('name', InputArgument::REQUIRED, 'Consumer Name') |
|
19
|
|
|
->setDescription('Delete a consumer\'s queue') |
|
20
|
|
|
->addOption('no-confirmation', null, InputOption::VALUE_NONE, 'Whether it must be confirmed before deleting'); |
|
21
|
|
|
|
|
22
|
|
|
$this->setName('rabbitmq:delete'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param InputInterface $input |
|
27
|
|
|
* @param OutputInterface $output |
|
28
|
|
|
* |
|
29
|
|
|
* @return int |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$noConfirmation = (bool) $input->getOption('no-confirmation'); |
|
34
|
|
|
|
|
35
|
|
|
if (!$noConfirmation && $input->isInteractive()) { |
|
36
|
|
|
$question = new ConfirmationQuestion( |
|
37
|
|
|
sprintf( |
|
38
|
|
|
'<question>Are you sure you wish to delete "%s" consumer\'s queue? (y/n)</question>', |
|
39
|
|
|
$input->getArgument('name') |
|
|
|
|
|
|
40
|
|
|
), |
|
41
|
|
|
false |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
if (!$this->getHelper('question')->ask($input, $output, $question)) { |
|
45
|
|
|
$output->writeln('<error>Deletion cancelled!</error>'); |
|
46
|
|
|
|
|
47
|
|
|
return 1; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$this->consumer = $this->getContainer() |
|
52
|
|
|
->get(sprintf($this->getConsumerService(), $input->getArgument('name'))); |
|
53
|
|
|
$this->consumer->delete(); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
return 0; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|