public function sendTestAction() { $document = Document\Newsletter::getById($this->getParam("id")); $addressSourceAdapterName = $this->getParam("addressAdapterName"); $adapterParams = json_decode($this->getParam("adapterParams"), true); $adapterClass = "\\Pimcore\\Document\\Newsletter\\AddressSourceAdapter\\" . ucfirst($addressSourceAdapterName); /** * @var $addressAdapter \Pimcore\Document\Newsletter\AddressSourceAdapterInterface */ $addressAdapter = new $adapterClass($adapterParams); $sendingContainer = $addressAdapter->getParamsForTestSending($this->getParam("testMailAddress")); $mail = \Pimcore\Tool\Newsletter::prepareMail($document); \Pimcore\Tool\Newsletter::sendNewsletterDocumentBasedMail($mail, $sendingContainer); $this->_helper->json(["success" => true]); }
protected function doSendMailInSingleMode(Model\Document\Newsletter $document, AddressSourceAdapterInterface $addressAdapter, $sendingId) { $totalCount = $addressAdapter->getTotalRecordCount(); //calculate page size based on total item count - with min page size 3 and max page size 10 $fifth = $totalCount / 5; $limit = $fifth > 10 ? 10 : ($fifth < 3 ? 3 : intval($fifth)); $offset = 0; $hasElements = true; while ($hasElements) { $tmpStore = Model\Tool\TmpStore::get($sendingId); $data = $tmpStore->getData(); Logger::info("Sending newsletter " . $hasElements . " / " . $totalCount . " [" . $document->getId() . "]"); $data['progress'] = round($offset / $totalCount * 100, 2); $tmpStore->setData($data); $tmpStore->update(); $sendingParamContainers = $addressAdapter->getParamsForSingleSending($limit, $offset); foreach ($sendingParamContainers as $sendingParamContainer) { $mail = \Pimcore\Tool\Newsletter::prepareMail($document, $sendingParamContainer); \Pimcore\Tool\Newsletter::sendNewsletterDocumentBasedMail($mail, $sendingParamContainer); if (empty($tmpStore)) { Logger::warn("Sending configuration for sending ID {$sendingId} was deleted. Cancelling sending process."); exit; } } $offset += $limit; $hasElements = count($sendingParamContainers); \Pimcore::collectGarbage(); } }