FlushQueueCommand.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Grav\Plugin\Console;
  3. use Grav\Common\Grav;
  4. use Grav\Console\ConsoleCommand;
  5. use Grav\Plugin\Email\Email;
  6. use Symfony\Component\Console\Input\InputOption;
  7. /**
  8. * Class FlushQueueCommand
  9. * @package Grav\Console\Cli\
  10. */
  11. class FlushQueueCommand extends ConsoleCommand
  12. {
  13. /** @var array */
  14. protected $options = [];
  15. /**
  16. * @return void
  17. */
  18. protected function configure()
  19. {
  20. $this
  21. ->setName('flush-queue')
  22. ->setAliases(['flushqueue'])
  23. ->addOption(
  24. 'env',
  25. 'e',
  26. InputOption::VALUE_OPTIONAL,
  27. 'The environment to trigger a specific configuration. For example: localhost, mysite.dev, www.mysite.com'
  28. )
  29. ->setDescription('Flushes the email queue of any pending emails')
  30. ->setHelp('The <info>flush-queue</info> command flushes the email queue of any pending emails');
  31. }
  32. /**
  33. * @return int
  34. */
  35. protected function serve()
  36. {
  37. // TODO: remove when requiring Grav 1.7+
  38. if (method_exists($this, 'initializeGrav')) {
  39. $this->initializeGrav();
  40. }
  41. $this->output->writeln('');
  42. $this->output->writeln('<yellow>Current Configuration:</yellow>');
  43. $this->output->writeln('');
  44. $grav = Grav::instance();
  45. dump($grav['config']->get('plugins.email'));
  46. $this->output->writeln('');
  47. require_once __DIR__ . '/../vendor/autoload.php';
  48. $output = Email::flushQueue();
  49. $this->output->writeln('<green>' . $output . '</green>');
  50. return 0;
  51. }
  52. }