Commit b953882f authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding pid field for sending mails. this field is now mandatory

parent 7fb15ad0
......@@ -120,6 +120,11 @@ class MailTemplateService {
*/
private $priority = Mail::PRIORITY_LOWEST;
/**
* @var int
*/
private $pid;
/**
* @var string
*/
......@@ -285,8 +290,10 @@ class MailTemplateService {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
public function sendEmail($isPreview = FALSE) {
$pageUid = (int) GeneralUtility::_GP('id');
$siteRootId = BackendService::getSiteRoot($pageUid);
if (!$this->pid) {
return FALSE;
}
$siteRootId = BackendService::getSiteRoot($this->pid);
/** @var Template $template */
$template = $this->templateRepository->findOneByTemplate(
......@@ -378,11 +385,14 @@ class MailTemplateService {
$currentTimestamp = $dateTime->getTimestamp();
$this->addMailToMailQueue(
$this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority,
$currentTimestamp, TRUE, $currentTimestamp, $this->language
$currentTimestamp, TRUE, $currentTimestamp, $this->language, $siteRootId
);
} else {
$this->addMailToMailQueue($this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority, 0, FALSE, 0, $this->language);
$this->addMailToMailQueue(
$this->extensionKey, $this->templateName, $subject, $emailBody, $this->priority, 0, FALSE, 0,
$this->language, $siteRootId
);
}
return TRUE;
......@@ -399,14 +409,16 @@ class MailTemplateService {
* @param int $priority
* @param int $lastSendingTime
* @param string $language
* @param int $pid
* @param bool $sent
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
private function addMailToMailQueue(
$extensionKey, $templateName, $subject, $emailBody, $priority, $sendingTime = 0, $sent = FALSE,
$lastSendingTime = 0, $language = 'en'
$lastSendingTime = 0, $language = 'en', $pid = 0
) {
$mail = $this->objectManager->get(Mail::class);
$mail->setPid($pid);
$mail->setExtensionKey($extensionKey);
$mail->setTemplateName($templateName);
$mail->setLanguage($language);
......@@ -656,4 +668,15 @@ class MailTemplateService {
LocalizationUtility::translate('backend.marker.type.mixed', 'sg_mail');
}
}
/**
* set the page id from which this was called
*
* @param int $pid
* @return MailTemplateService
*/
public function setPid($pid) {
$this->pid = (int) $pid;
return $this;
}
}
......@@ -64,6 +64,9 @@ Example:
$mailService->setIgnoreMailQueue(TRUE);
$mailService->setMarkers(['link' => $uri]);
// set the pageId (mandatory since version 4.0!!!)
$mailService->setPid(123);
// set the proper language for the mail
$mailService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment