Exemplo n.º 1
0
 /**
  * @TODO: Move to event
  *
  * @param CampaignEntity $entity
  * @param MessageEntity  $message
  *
  * @return bool
  */
 private function handleSystemMessage(CampaignEntity $entity, MessageEntity $message)
 {
     if ($message->getBody() && $message->getSubject()) {
         if (!$message->getId()) {
             $message->setCampaign($entity);
             $message->setQueuedAt(new \DateTime('now'));
             $message->setSendAt(new \DateTime('now'));
             $message->setOnHalt(false);
             $message->setSystemMessage(true);
             $this->systemMessageOp = static::SYSTEM_MESSAGE_CREATED;
         } else {
             $this->systemMessageOp = static::SYSTEM_MESSAGE_UPDATED;
         }
         $this->entityManager->persist($message);
     } elseif ($message->getId()) {
         $this->systemMessageOp = static::SYSTEM_MESSAGE_DELETED;
         $this->entityManager->remove($message);
     } else {
         $this->systemMessageOp = static::SYSTEM_MESSAGE_SKIPPED;
     }
     return true;
 }