示例#1
0
 /**
  * If batching is supported and enabled, the message will be queued and will on be sent upon flushQueue().
  * Otherwise, the message will be sent to the transport immediately
  *
  * @param bool   $dispatchSendEvent
  * @param string $immediateSendMessageHandling If tokenization is not supported by the mailer, this argument determines
  *                                             what should happen to $this->message after the email send is attempted.
  *                                             Options are:
  *                                             RESET_TO           resets the to recipients and resets errors
  *                                             FULL_RESET         creates a new MauticMessage instance and resets errors
  *                                             DO_NOTHING         leaves the current errors array and MauticMessage instance intact
  *                                             NOTHING_IF_FAILED  leaves the current errors array MauticMessage instance intact if it fails, otherwise reset_to
  *
  *
  *
  * @return bool
  */
 public function queue($dispatchSendEvent = false, $immediateSendMessageHandling = 'RESET_TO')
 {
     if ($this->tokenizationEnabled) {
         // Dispatch event to get custom tokens from listeners
         if ($dispatchSendEvent) {
             $this->dispatchSendEvent();
         }
         // Metadata has to be set for each recipient
         foreach ($this->queuedRecipients as $email => $name) {
             $this->message->addMetadata($email, array('leadId' => !empty($this->lead) ? $this->lead['id'] : null, 'emailId' => !empty($this->email) ? $this->email->getId() : null, 'hashId' => $this->idHash, 'source' => $this->source, 'tokens' => $this->getTokens()));
         }
         // Add asset stats if applicable
         $this->queueAssetDownloadEntry();
         // Reset recipients
         $this->queuedRecipients = array();
         // Assume success
         return true;
     } else {
         $success = $this->send($dispatchSendEvent);
         // Reset the message for the next
         $this->queuedRecipients = array();
         // Reset message
         switch (ucwords($immediateSendMessageHandling)) {
             case 'RESET_TO':
                 $this->message->setTo(array());
                 $this->clearErrors();
                 break;
             case 'NOTHING_IF_FAILED':
                 if ($success) {
                     $this->message->setTo(array());
                     $this->clearErrors();
                 }
                 break;
             case 'FULL_RESET':
                 $this->message = $this->getMessageInstance();
                 $this->attachedAssets = array();
                 $this->clearErrors();
                 break;
             case 'DO_NOTHING':
             default:
                 // Nada
                 break;
         }
         return $success;
     }
 }