_cache, 'clearAll')) { $this->_cache->clearAll($this->_cacheKey); }*/ } /** * Tests if this Spool mechanism has started. * * @return bool */ public function isStarted() { return true; } /** * Starts this Spool mechanism. */ public function start() { } /** * Stops this Spool mechanism. */ public function stop() { } /** * Allow to manage the enqueuing retry limit. * * Default, is ten and allows over 64^20 different fileNames * * @param int $limit */ public function setRetryLimit($limit) { $this->_retryLimit = $limit; } /** * Queues a message. * * @param Swift_Mime_Message $message The message to store * * @return bool * * @throws Swift_IoException */ public function queueMessage(\Swift_Mime_Message $message) { $message->getBody(); $queueObject = new MailerQueue(); $queueObject->text_body = $message->getBody(); $queueObject->subject = $message->getSubject(); $queueObject->to = Json::encode($message->getTo()); $queueObject->save(); } /** * Sends messages using the given transport instance. * * @param Swift_Transport $transport A transport instance * @param string[] $failedRecipients An array of failures by-reference * * @return int The number of sent e-mail's */ public function flushQueue(\Swift_Transport $transport, &$failedRecipients = null) { if (!$transport->isStarted()) { $transport->start(); } $failedRecipients = (array) $failedRecipients; $count = 0; $emails = MailerQueue::find() ->where('sent_time IS NULL') ->orderBy('id') ->all(); if (!count($emails)) { return 0; } // print_r($emails); foreach($emails as $email) { //$message = unserialize($email->message_object); $message = \Swift_Message::newInstance($email->subject) ->setFrom(array('info@example.com' => 'ArtWeb')) ->setTo(Json::decode($email->to)) ->setBody($email->text_body); try { $count+= $transport->send($message, $failedRecipients); if($count > 0) { $time = new \DateTime(); $email->setAttribute('sent_time', $time->format('Y-m-d H:i:s')); $email->save(); } else { throw new \Swift_SwiftException('The email was not sent.'); } } catch(\Swift_SwiftException $ex) { } } return $count; } }