Esempio n. 1
0
 /**
  * Spool a newsletter page out to the real receivers.
  *
  * @global \TYPO3\CMS\Core\Database\DatabaseConnection $TYPO3_DB
  * @param Newsletter $newsletter
  */
 public static function createSpool(Newsletter $newsletter)
 {
     // If newsletter is locked because spooling now, or already spooled, then skip
     if ($newsletter->getBeginTime()) {
         return;
     }
     $newsletterRepository = self::getNewsletterRepository();
     // Lock the newsletter by setting its begin_time
     $beginTime = new DateTime();
     $newsletter->setBeginTime($beginTime);
     $newsletterRepository->updateNow($newsletter);
     $emailSpooledCount = 0;
     $recipientList = $newsletter->getRecipientList();
     $recipientList->init();
     $databaseConnection = self::getDatabaseConnection();
     while ($receiver = $recipientList->getRecipient()) {
         // Register the recipient
         if (GeneralUtility::validEmail($receiver['email'])) {
             $databaseConnection->exec_INSERTquery('tx_newsletter_domain_model_email', ['pid' => $newsletter->getPid(), 'recipient_address' => $receiver['email'], 'recipient_data' => serialize($receiver), 'newsletter' => $newsletter->getUid()]);
             $databaseConnection->exec_UPDATEquery('tx_newsletter_domain_model_email', 'uid = ' . intval($databaseConnection->sql_insert_id()), ['auth_code' => 'MD5(CONCAT(uid, recipient_address))'], ['auth_code']);
             ++$emailSpooledCount;
         }
     }
     self::getLogger(__CLASS__)->info("Queued {$emailSpooledCount} emails to be sent for newsletter " . $newsletter->getUid());
     // Schedule repeated newsletter if any
     $newsletter->scheduleNextNewsletter();
     // Unlock the newsletter by setting its end_time
     $newsletter->setEndTime(new DateTime());
     $newsletterRepository->updateNow($newsletter);
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function setBeginTimeForDateTimeSetsBeginTime()
 {
     $dateTimeFixture = new \DateTime();
     $this->subject->setBeginTime($dateTimeFixture);
     $this->assertAttributeEquals($dateTimeFixture, 'beginTime', $this->subject);
 }
Esempio n. 3
0
 /**
  * Spool a newsletter page out to the real receivers.
  *
  * @global \TYPO3\CMS\Core\Database\DatabaseConnection $TYPO3_DB
  * @param   array        Newsletter record.
  * @param   integer      Actual begin time.
  * @return  void
  */
 public static function createSpool(Newsletter $newsletter)
 {
     global $TYPO3_DB;
     // If newsletter is locked because spooling now, or already spooled, then skip
     if ($newsletter->getBeginTime()) {
         return;
     }
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $newsletterRepository = $objectManager->get('Ecodev\\Newsletter\\Domain\\Repository\\NewsletterRepository');
     // Lock the newsletter by setting its begin_time
     $begintime = new DateTime();
     $newsletter->setBeginTime($begintime);
     $newsletterRepository->updateNow($newsletter);
     $emailSpooledCount = 0;
     $recipientList = $newsletter->getRecipientList();
     $recipientList->init();
     while ($receiver = $recipientList->getRecipient()) {
         // Register the receiver
         if (\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($receiver['email'])) {
             $TYPO3_DB->exec_INSERTquery('tx_newsletter_domain_model_email', array('pid' => $newsletter->getPid(), 'recipient_address' => $receiver['email'], 'recipient_data' => serialize($receiver), 'pid' => $newsletter->getPid(), 'newsletter' => $newsletter->getUid()));
             $emailSpooledCount++;
         }
     }
     self::log("Queued {$emailSpooledCount} emails to be sent for newsletter " . $newsletter->getUid());
     // Schedule repeated newsletter if any
     $newsletter->scheduleNextNewsletter();
     // Unlock the newsletter by setting its end_time
     $newsletter->setEndTime(new DateTime());
     $newsletterRepository->updateNow($newsletter);
 }