Esempio n. 1
0
 public function setNewsletter(Newsletter $newsletter, $language = null)
 {
     $domain = $newsletter->getDomain();
     // When sending newsletter via scheduler (so via CLI mode) realurl cannot guess
     // the domain name by himself, so we help him by filling HTTP_HOST variable
     $_SERVER['HTTP_HOST'] = $domain;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $this->siteUrl = "http://{$domain}/";
     $this->linksCache = array();
     $this->newsletter = $newsletter;
     $this->homeUrl = $this->siteUrl . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('newsletter');
     $this->senderName = $newsletter->getSenderName();
     $this->senderEmail = $newsletter->getSenderEmail();
     $bounceAccount = $newsletter->getBounceAccount();
     $this->bounceAddress = $bounceAccount ? $bounceAccount->getEmail() : '';
     // Build html
     $validatedContent = $newsletter->getValidatedContent($language);
     if (count($validatedContent['errors'])) {
         throw new Exception('The newsletter HTML content does not validate. The sending is aborted. See errors: ' . serialize($validatedContent['errors']));
     }
     $this->setHtml($validatedContent['content']);
     // Build title from HTML source (we cannot use $newsletter->getTitle(), because it is NOT localized)
     $this->setTitle($validatedContent['content']);
     // Attaching files
     $files = $newsletter->getAttachments();
     foreach ($files as $file) {
         if (trim($file) != '') {
             $filename = PATH_site . "uploads/tx_newsletter/{$file}";
             $this->attachments[] = Swift_Attachment::fromPath($filename);
         }
     }
 }
Esempio n. 2
0
 /**
  * Creates a new Newsletter and forwards to the list action.
  *
  * @param \Ecodev\Newsletter\Domain\Model\Newsletter $newNewsletter a fresh Newsletter object which has not yet been added to the repository
  * @dontverifyrequesthash
  * @dontvalidate $newNewsletter
  * @ignorevalidation $newNewsletter
  */
 public function createAction(Newsletter $newNewsletter = null)
 {
     $limitTestRecipientCount = 10;
     // This is a low limit, technically, but it does not make sense to test a newsletter for more people than that anyway
     $recipientList = $newNewsletter->getRecipientList();
     $recipientList->init();
     $count = $recipientList->getCount();
     $validatedContent = $newNewsletter->getValidatedContent($language);
     // If we attempt to create a newsletter as a test but it has too many recipient, reject it (we cannot safely send several emails wihtout slowing down respoonse and/or timeout issues)
     if ($newNewsletter->getIsTest() && $count > $limitTestRecipientCount) {
         $this->addFlashMessage($this->translate('flashmessage_test_maximum_recipients', [$count, $limitTestRecipientCount]), $this->translate('flashmessage_test_maximum_recipients_title'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $this->view->assign('success', false);
     } elseif (count($validatedContent['errors'])) {
         $this->addFlashMessage('The newsletter HTML content does not validate. See tab "Newsletter > Status" for details.', $this->translate('flashmessage_newsletter_invalid'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $this->view->assign('success', false);
     } else {
         // If it's a test newsletter, it's planned to be sent right now
         if ($newNewsletter->getIsTest()) {
             $newNewsletter->setPlannedTime(new DateTime());
         }
         // Save the new newsletter
         $this->newsletterRepository->add($newNewsletter);
         $this->persistenceManager->persistAll();
         $this->view->assign('success', true);
         // If it is test newsletter, send it immediately
         if ($newNewsletter->getIsTest()) {
             try {
                 // Fill the spool and run the queue
                 Tools::createSpool($newNewsletter);
                 Tools::runSpool($newNewsletter);
                 $this->addFlashMessage($this->translate('flashmessage_test_newsletter_sent'), $this->translate('flashmessage_test_newsletter_sent_title'), \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
             } catch (\Exception $exception) {
                 $this->addFlashMessage($exception->getMessage(), $this->translate('flashmessage_test_newsletter_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
             }
         } else {
             $this->addFlashMessage($this->translate('flashmessage_newsletter_queued'), $this->translate('flashmessage_newsletter_queued_title'), \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
         }
     }
     $this->view->setVariablesToRender(['data', 'success', 'flashMessages']);
     $this->view->setConfiguration(['data' => self::resolveJsonViewConfiguration()]);
     $this->view->assign('data', $newNewsletter);
     $this->flushFlashMessages();
 }