Esempio n. 1
0
 /**
  * Send an email to lead lists
  *
  * @param Email $email
  * @param array $lists
  * @param int   $limit
  * @return array array(int $sentCount, int $failedCount, array $failedRecipientsByList)
  */
 public function sendEmailToLists(Email $email, $lists = null, $limit = null)
 {
     //get the leads
     if (empty($lists)) {
         $lists = $email->getLists();
     }
     //get email settings such as templates, weights, etc
     $emailSettings = $this->getEmailSettings($email);
     $options = array('source' => array('email', $email->getId()), 'emailSettings' => $emailSettings, 'allowResends' => false, 'customHeaders' => array('Precedence' => 'Bulk'));
     $failed = array();
     $sentCount = 0;
     $failedCount = 0;
     foreach ($lists as $list) {
         if ($limit !== null && $limit <= 0) {
             // Hit the max for this batch
             break;
         }
         $options['listId'] = $list->getId();
         $leads = $this->getPendingLeads($email, $list->getId(), false, $limit);
         $leadCount = count($leads);
         $sentCount += $leadCount;
         if ($limit != null) {
             // Only retrieve the difference between what has already been sent and the limit
             $limit -= $leadCount;
         }
         $listErrors = $this->sendEmail($email, $leads, $options);
         if (!empty($listErrors)) {
             $listFailedCount = count($listErrors);
             $sentCount -= $listFailedCount;
             $failedCount += $listFailedCount;
             $failed[$options['listId']] = $listErrors;
         }
     }
     return array($sentCount, $failedCount, $failed);
 }
 /**
  * {@inheritDoc}
  */
 public function getLists()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getLists', array());
     return parent::getLists();
 }
Esempio n. 3
0
 /**
  * Send an email to lead lists
  *
  * @param Email $email
  * @param array $lists
  * @param int   $limit
  *
  * @return array array(int $sentCount, int $failedCount, array $failedRecipientsByList)
  */
 public function sendEmailToLists(Email $email, $lists = null, $limit = null)
 {
     //get the leads
     if (empty($lists)) {
         $lists = $email->getLists();
     }
     $options = ['source' => ['email', $email->getId()], 'allowResends' => false, 'customHeaders' => ['Precedence' => 'Bulk']];
     $failed = [];
     $sentCount = 0;
     $failedCount = 0;
     foreach ($lists as $list) {
         if ($limit !== null && $limit <= 0) {
             // Hit the max for this batch
             break;
         }
         $options['listId'] = $list->getId();
         $leads = $this->getPendingLeads($email, $list->getId(), false, $limit);
         $leadCount = count($leads);
         $sentCount += $leadCount;
         if ($limit != null) {
             // Only retrieve the difference between what has already been sent and the limit
             $limit -= $leadCount;
         }
         $listErrors = $this->sendEmail($email, $leads, $options);
         if (!empty($listErrors)) {
             $listFailedCount = count($listErrors);
             $sentCount -= $listFailedCount;
             $failedCount += $listFailedCount;
             $failed[$options['listId']] = $listErrors;
         }
     }
     return [$sentCount, $failedCount, $failed];
 }
Esempio n. 4
0
 /**
  * Send an email to lead lists.
  *
  * @param Email $email
  * @param array $lists
  * @param int   $limit
  * @param bool  $batch True to process and batch all pending leads
  *
  * @return array array(int $sentCount, int $failedCount, array $failedRecipientsByList)
  */
 public function sendEmailToLists(Email $email, $lists = null, $limit = null, $batch = false, OutputInterface $output = null)
 {
     //get the leads
     if (empty($lists)) {
         $lists = $email->getLists();
     }
     $options = ['source' => ['email', $email->getId()], 'allowResends' => false, 'customHeaders' => ['Precedence' => 'Bulk']];
     $failed = [];
     $sentCount = 0;
     $failedCount = 0;
     $progress = false;
     if ($batch && $output) {
         $progressCounter = 0;
         $totalLeadCount = $this->getPendingLeads($email, null, true);
         if (!$totalLeadCount) {
             return;
         }
         // Broadcast send through CLI
         $output->writeln("\n<info>" . $email->getName() . '</info>');
         $progress = new ProgressBar($output, $totalLeadCount);
     }
     foreach ($lists as $list) {
         if (!$batch && $limit !== null && $limit <= 0) {
             // Hit the max for this batch
             break;
         }
         $options['listId'] = $list->getId();
         $leads = $this->getPendingLeads($email, $list->getId(), false, $limit);
         $leadCount = count($leads);
         while ($leadCount) {
             $sentCount += $leadCount;
             if (!$batch && $limit != null) {
                 // Only retrieve the difference between what has already been sent and the limit
                 $limit -= $leadCount;
             }
             $listErrors = $this->sendEmail($email, $leads, $options);
             if (!empty($listErrors)) {
                 $listFailedCount = count($listErrors);
                 $sentCount -= $listFailedCount;
                 $failedCount += $listFailedCount;
                 $failed[$options['listId']] = $listErrors;
             }
             if ($batch) {
                 if ($progress) {
                     $progressCounter += $leadCount;
                     $progress->setProgress($progressCounter);
                 }
                 // Get the next batch of leads
                 $leads = $this->getPendingLeads($email, $list->getId(), false, $limit);
                 $leadCount = count($leads);
             } else {
                 $leadCount = 0;
             }
         }
     }
     if ($progress) {
         $progress->finish();
     }
     return [$sentCount, $failedCount, $failed];
 }