addOptions(array( new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'), new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'), new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), )); $this->namespace = 'send'; $this->name = 'bulletin'; $this->briefDescription = 'Rozesle bulletin.'; $this->detailedDescription = ''; } protected function execute($arguments = array(), $options = array()) { sfContext::createInstance($this->configuration); $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $this->configuration->loadHelpers(array('Partial')); $subcribers = Doctrine::getTable('Subscriber')->findAll(); $query = Doctrine::getTable('Bulletin')->createQuery() ->addWhere('is_planned = ?', TRUE) ->addWhere('planned_date <= ?', date('Y-m-d')); foreach($query->execute() as $bulletin) { $m = new Swift_Message($bulletin->getSubject()); $m->setFrom(sfConfig::get('app_mail_from_address')); $m->setContentType('text/html'); if($bulletin->hasFile()) { $m->attach(new Swift_Attachment(file_get_contents($bulletin->getPath()), $bulletin->getNiceFilename())); } foreach($subcribers as $subscriber) { // if($subscriber->getId() == 1) continue; $body = get_component('bulletin', 'mailBody', array('bulletin' => $bulletin, 'subscriber' => $subscriber)); $m->setBody($body); $m->setTo($subscriber->getEmail()); //$m->setTo('tomas.naibrt@gmail.com'); $this->getMailer()->send($m); $this->logSection('send', $subscriber->getEmail()); } $bulletin->setSubscribersNum(count($subcribers)); $bulletin->setIsPlanned(false); $bulletin->setSendDate(date('Y-m-d H:i:s')); $bulletin->save(); $this->logSection('send', $bulletin->getSubject().'('.$bulletin->getSubscribersNum().'x)'); } } }