public function sendAction()
{
$document = Document\Newsletter::getById($this->getParam("id"));
if (Tool\TmpStore::get($document->getTmpStoreId())) {
throw new Exception("newsletter sending already in progress, need to finish first.");
}
$document = Document\Newsletter::getById($this->getParam("id"));
Tool\TmpStore::add($document->getTmpStoreId(), ['documentId' => $document->getId(), 'addressSourceAdapterName' => $this->getParam("addressAdapterName"), 'adapterParams' => json_decode($this->getParam("adapterParams"), true), 'inProgress' => false, 'progress' => 0], 'newsletter');
\Pimcore\Tool\Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:newsletter-document-send " . escapeshellarg($document->getTmpStoreId()) . " " . escapeshellarg(\Pimcore\Tool::getHostUrl()), PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "newsletter-sending-output.log");
$this->_helper->json(["success" => true]);
}