1. sfProjectSendEmailsTask.class.php
  2. /** * Send emails stored in a queue. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfProjectSendEmailsTask.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfProjectSendEmailsTask extends sfBaseTask
  4. {
  5. /**
  6. * @see sfTask
  7. */
  8. protected function configure()
  9. {
  10. $this->addOptions(array(
  11. new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
  12. new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
  13. new sfCommandOption('message-limit', null, sfCommandOption::PARAMETER_OPTIONAL, 'The maximum number of messages to send', 0),
  14. new sfCommandOption('time-limit', null, sfCommandOption::PARAMETER_OPTIONAL, 'The time limit for sending messages (in seconds)', 0),
  15. ));
  16. $this->namespace = 'project';
  17. $this->name = 'send-emails';
  18. $this->briefDescription = 'Sends emails stored in a queue';
  19. $this->detailedDescription = <<<EOF
  20. The [project:send-emails|INFO] sends emails stored in a queue:
  21. [php symfony project:send-emails|INFO]
  22. You can limit the number of messages to send:
  23. [php symfony project:send-emails --message-limit=10|INFO]
  24. Or limit to time (in seconds):
  25. [php symfony project:send-emails --time-limit=10|INFO]
  26. EOF;
  27. }
  28. protected function execute($arguments = array(), $options = array())
  29. {
  30. $databaseManager = new sfDatabaseManager($this->configuration);
  31. $spool = $this->getMailer()->getSpool();
  32. $spool->setMessageLimit($options['message-limit']);
  33. $spool->setTimeLimit($options['time-limit']);
  34. $sent = $this->getMailer()->flushQueue();
  35. $this->logSection('project', sprintf('sent %s emails', $sent));
  36. }
  37. }

Debug toolbar