示例#1
0
 /**
  * @param QueueItem $queueItem
  */
 protected function safeSend(QueueItem $queueItem)
 {
     $now = new \DateTime("now");
     $queueItem->setAckedAt($now);
     $this->saveQueueItem($queueItem);
     $message = $queueItem->getMessage();
     $campaign = $message->getCampaign();
     $template = $campaign->getTemplate();
     $subscriber = $queueItem->getSubscriber();
     $this->messageBuilder->setEntityVars($message, $campaign, $template, $subscriber, $queueItem);
     $headers = $this->messageBuilder->getHeaders();
     $messageBody = $this->messageBuilder->getBody($message->getBody(), $template->getBody());
     $subject = $this->messageBuilder->template($message->getSubject());
     $this->mail($subscriber, $campaign, $subject, $messageBody, $headers);
     $queueItem->setSentAt($now);
     $this->saveQueueItem($queueItem);
 }
 /**
  * @param QueueItem $queueItem
  *
  * @return string
  */
 private function prepareMessageBuilder(QueueItem $queueItem)
 {
     $message = $queueItem->getMessage();
     $campaign = $message->getCampaign();
     $template = $campaign->getTemplate();
     $subscriber = $queueItem->getSubscriber();
     $this->messageBuilder->setEntityVars($message, $campaign, $template, $subscriber, $queueItem);
 }
示例#3
0
 /**
  * @param Entity\Message $message
  *
  * @return Entity\QueueItem[]
  */
 protected function getOldAckedQueue(Entity\Message $message)
 {
     $longAgo = new \DateTime('-1 hour');
     $queueItems = [];
     foreach ($this->getSubscribers() as $subscriber) {
         $queueItem = new Entity\QueueItem();
         $queueItem->setSystemMessage(false);
         $queueItem->setAckedAt($longAgo);
         $queueItem->setSubscriber($subscriber);
         $queueItem->setMessage($message);
         $queueItem->setSecurityKey();
         $queueItems[] = $queueItem;
     }
     return $queueItems;
 }
示例#4
0
 /**
  * @param QueueItem $queueItem
  *
  * @return string
  */
 private function queueItemToString(QueueItem $queueItem)
 {
     $subject = $queueItem->getMessage()->getSubject();
     $emailAddress = $queueItem->getSubscriber()->getEmailAddress();
     return sprintf("%d. (%s -> %s)\n", $queueItem->getId(), $subject, $emailAddress);
 }
 /**
  * @param array $messages    Entity\Message[]
  * @param array $subscribers Entity\Subscriber[]
  *
  * @return array Entity\Queue[]
  */
 protected function getQueue(array $messages, array $subscribers)
 {
     $time = time();
     $queue = [];
     /** @var Entity\Message $message */
     foreach ($messages as $message) {
         if (!$message->getQueuedAt()) {
             continue;
         }
         $queuedAt = $message->getQueuedAt()->format('U');
         if ($queuedAt > $time) {
             continue;
         }
         foreach ($subscribers as $subscriber) {
             if (!$this->isSubscriberSubscribedToCampaign($message, $subscriber)) {
                 continue;
             }
             $queueItem = new Entity\QueueItem();
             $this->queueItemId++;
             $queueItem->setMessage($message);
             $queueItem->setSubscriber($subscriber);
             $queueItem->setSecurityKey($this->getUniqueSecurityKey());
             $queueItem->setSystemMessage($this->isSystemMessage());
             if ($queuedAt + 300 < $time) {
                 $ackedAt = new \DateTime();
                 $ackedAt->setTimestamp($queuedAt + 300);
                 $queueItem->setAckedAt($ackedAt);
             }
             if ($queuedAt + 600 < $time && $message->getClosedAt()) {
                 $sentAt = new \DateTime();
                 $sentAt->setTimestamp($queuedAt + 600);
                 $queueItem->setSentAt($sentAt);
             }
             $queue[] = $queueItem;
         }
     }
     return $queue;
 }
示例#6
0
 /**
  * @param QueueItem $queueItem
  *
  * @return string
  */
 private function getTrackingUrl(QueueItem $queueItem)
 {
     $params = ['securityKey' => $queueItem->getSecurityKey()];
     $options = ['force_canonical' => true];
     return $this->fakeUrl->fromRoute('queue/track', $params, $options);
 }