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