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