예제 #1
0
 /**
  * @param string $securityKey
  *
  * @return bool
  */
 public function trackQueueItem($securityKey)
 {
     $queueItem = $this->mainRepository->getOneBySecurityKey($securityKey);
     if ($queueItem) {
         $queueItem->setIsTracked(true);
         return $this->saveEntity($queueItem);
     }
     return false;
 }
예제 #2
0
 private function populateThrottleCounts()
 {
     foreach ($this->converted as $seconds => $convertedOption) {
         $max = $this->converted[$seconds][static::MAX];
         $count = $this->queueItemRepository->getUnsentQueueSize($convertedOption[static::DATETIME]);
         $diff = max(0, $max - $count);
         $this->converted[$seconds][static::COUNT] = $count;
         $this->converted[$seconds][static::DIFF] = $diff;
         $this->throttleCounts[$seconds] = $diff;
     }
 }
예제 #3
0
 /**
  * @TODO: Move queue messages into an event
  *
  * @param Entity\Subscriber   $subscriber
  * @param Entity\Message|null $systemMessage
  *
  * @return bool
  */
 public function queueMessage(Entity\Subscriber $subscriber, Entity\Message $systemMessage = null)
 {
     if (!$systemMessage) {
         return false;
     }
     /** @var Entity\QueueItem $queueItem */
     $queueItem = $this->queueItemRepository->getNewEntity();
     $queueItem->setMessage($systemMessage);
     $queueItem->setSubscriber($subscriber);
     $queueItem->setDefaultSecurityKey();
     $this->entityManager->persist($queueItem);
     $this->entityManager->persist($systemMessage);
     return true;
 }
예제 #4
0
 /**
  * @return string
  */
 public function createQueueAction()
 {
     $readyMessages = $this->messageRepository->getReadyToBeQueued();
     foreach ($readyMessages as $message) {
         $queueCount = $this->queueItemRepository->queueMessage($message);
         if ($this->isVerbose()) {
             $this->logger->info('Message to be queued: ' . $this->messageToString($message, $queueCount));
         }
     }
     if ($this->hasCacheStorage()) {
         $this->cacheStorage->setItem(\DmMailer\View\DataProvider\Kpi::CS_LAST_QUEUE_CREATION, $this->getTime());
     }
     return '';
 }
예제 #5
0
 /**
  * @return ViewModel
  */
 public function previewAction()
 {
     /** @var QueueItem $queueItem */
     $queueItem = $this->queueItemRepository->getOneBySecurityKey($this->params('securityKey'));
     if (!$queueItem) {
         return $this->redirect()->toRoute(static::ERROR_ROUTE);
     }
     $this->prepareMessageBuilder($queueItem);
     $message = $queueItem->getMessage();
     $template = $message->getCampaign()->getTemplate();
     $previewData = $this->messageBuilder->getBody($message->getBody(), $template->getBody());
     $this->layout('layout/empty');
     return new ViewModel(['preview' => $previewData]);
 }
예제 #6
0
 /**
  * @param MessageEntity    $message
  * @param SubscriberEntity $subscriber
  */
 private function createItem(MessageEntity $message, SubscriberEntity $subscriber)
 {
     /** @var QueueItemEntity $queueItem */
     $queueItem = $this->queueItemRepository->getNewEntity();
     $queueItem->setMessage($message);
     $queueItem->setSubscriber($subscriber);
     $queueItem->setSystemMessage(true);
     $queueItem->setSecurityKey();
     $this->saveEntity($queueItem, false);
 }
예제 #7
0
 /**
  * @covers DmMailer\Repository\QueueItem
  */
 public function testQueueMessage()
 {
     $oldQueueSize = count($this->sut->findAll());
     $campaign = $this->campaignRepo->findOneBy(['entityId' => 1]);
     $message = $this->messageRepo->getNewEntity();
     $message->setSubject('Subject');
     $message->setBody('Body');
     $message->setCampaign($campaign);
     $this->sut->queueMessage($message);
     $newQueueSize = count($this->sut->findAll());
     $this->assertGreaterThan($oldQueueSize, $newQueueSize);
     $this->assertEquals($oldQueueSize + count($campaign->getSubscribers()), $newQueueSize);
 }
예제 #8
0
 /**
  * @return string
  */
 public function cleanUpAction()
 {
     $readyQueue = $this->queueItemRepository->getSuspiciousQueue();
     if ($this->isVerbose()) {
         if (empty($readyQueue)) {
             $this->logger->info('Nothing to fix.');
         } else {
             foreach ($readyQueue as $queueItem) {
                 $this->logger->info('Fixing queue item: ' . $this->queueItemToString($queueItem));
             }
         }
     }
     $this->queueItemRepository->fixSuspiciousQueue($readyQueue);
     return '';
 }
예제 #9
0
파일: Kpi.php 프로젝트: peteraba/dm-mailer
 /**
  * @return array
  */
 private function getUnackedQueueSize()
 {
     $count = $this->queueItemRepo->getUnackedQueueSize();
     $kpiType = self::INFO;
     return [self::UNACKED_QUEUE_SIZE => [self::VALUE => $count, self::TYPE => $kpiType]];
 }