Esempio n. 1
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;
 }
 /**
  * @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;
 }