protected function doSendMailInBatchMode(Model\Document\Newsletter $document, AddressSourceAdapterInterface $addressAdapter, $sendingId)
{
$mail = \Pimcore\Tool\Newsletter::prepareMail($document);
$sendingParamContainers = $addressAdapter->getMailAddressesForBatchSending();
$currentCount = 0;
$totalCount = $addressAdapter->getTotalRecordCount();
//calculate page size based on total item count - with min page size 3 and max page size 10
$fifth = $totalCount / 5;
$pageSize = $fifth > 10 ? 10 : ($fifth < 3 ? 3 : intval($fifth));
foreach ($sendingParamContainers as $sendingParamContainer) {
$tmpStore = Model\Tool\TmpStore::get($sendingId);
if (empty($tmpStore)) {
Logger::warn("Sending configuration for sending ID {$sendingId} was deleted. Cancelling sending process.");
exit;
}
if ($currentCount % $pageSize == 0) {
Logger::info("Sending newsletter " . $currentCount . " / " . $totalCount . " [" . $document->getId() . "]");
$data = $tmpStore->getData();
$data['progress'] = round($currentCount / $totalCount * 100, 2);
$tmpStore->setData($data);
$tmpStore->update();
\Pimcore::collectGarbage();
}
\Pimcore\Tool\Newsletter::sendNewsletterDocumentBasedMail($mail, $sendingParamContainer);
$currentCount++;
}
}