FlushQueueCommand.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  14. * @var array
  15. */
  16. protected $options = [];
  17. /**
  18. *
  19. */
  20. protected function configure()
  21. {
  22. $this
  23. ->setName('flush-queue')
  24. ->setAliases(['flushqueue'])
  25. ->addOption(
  26. 'env',
  27. 'e',
  28. InputOption::VALUE_OPTIONAL,
  29. 'The environment to trigger a specific configuration. For example: localhost, mysite.dev, www.mysite.com'
  30. )
  31. ->setDescription('Flushes the email queue of any pending emails')
  32. ->setHelp('The <info>flush-queue</info> command flushes the email queue of any pending emails');
  33. }
  34. /**
  35. * @return int|null|void
  36. */
  37. protected function serve()
  38. {
  39. // TODO: remove when requiring Grav 1.7+
  40. if (method_exists($this, 'initializeGrav')) {
  41. $this->initializeGrav();
  42. }
  43. $grav = Grav::instance();
  44. $this->output->writeln('');
  45. $this->output->writeln('<yellow>Current Configuration:</yellow>');
  46. $this->output->writeln('');
  47. dump($grav['config']->get('plugins.email'));
  48. $this->output->writeln('');
  49. require_once __DIR__ . '/../vendor/autoload.php';
  50. $output = Email::flushQueue();
  51. $this->output->writeln('<green>' . $output . '</green>');
  52. }
  53. }