Skip to content
Snippets Groups Projects
Commit 9c9b5d26 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Fixing test Mail

parent 6bb8e718
No related branches found
No related tags found
No related merge requests found
......@@ -168,6 +168,7 @@ class MailController extends ActionController {
if ($templateLeft !== NULL) {
$this->view->assign('contentLeft', $templateLeft->getContent());
$this->view->assign('subjectLeft', $templateLeft->getSubject());
} else {
$defaultTemplatePath = MailTemplateService::getRegisterArray()
[$selectedExtension][$selectedTemplate]['templatePath'];
......@@ -190,6 +191,7 @@ class MailController extends ActionController {
if ($templateRight !== NULL) {
$this->view->assign('contentRight', $templateRight->getContent());
$this->view->assign('subjectRight', $templateRight->getSubject());
} else {
$defaultTemplatePath = MailTemplateService::getRegisterArray()
[$selectedExtension][$selectedTemplate]['templatePath'];
......@@ -333,12 +335,9 @@ class MailController extends ActionController {
* @param string $selectedExtensionKey
* @param string $selectedLanguageLeft
* @param string $selectedLanguageRight
* @param string $contentRight
* @param string $contentLeft
*/
public function sendTestMailAction(
$emailAddress, $selectedExtensionKey, $selectedTemplateKey, $selectedLanguageLeft, $selectedLanguageRight,
$contentRight, $contentLeft
$emailAddress, $selectedExtensionKey, $selectedTemplateKey, $selectedLanguageLeft, $selectedLanguageRight
) {
if (!filter_var($this->settings['mail']['test']['from'], FILTER_VALIDATE_EMAIL)) {
......@@ -357,7 +356,7 @@ class MailController extends ActionController {
$mailTemplateService->setFromAddress($this->settings['mail']['test']['from']);
$mailTemplateService->setTemplateName($selectedTemplateKey);
$mailTemplateService->setExtensionKey($selectedExtensionKey);
$mailIsSend = $mailTemplateService->sendPreviewMail($this->settings['mail']['test']['subject']);
$mailIsSend = $mailTemplateService->sendEmail($this->settings['mail']['test']['subject'], TRUE);
if ($selectedLanguageRight !== $selectedLanguageLeft) {
/** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */
......@@ -367,7 +366,7 @@ class MailController extends ActionController {
$mailTemplateService->setFromAddress($this->settings['mail']['test']['from']);
$mailTemplateService->setTemplateName($selectedTemplateKey);
$mailTemplateService->setExtensionKey($selectedExtensionKey);
$mailIsSend = $mailTemplateService->sendPreviewMail($this->settings['mail']['test']['subject']);
$mailIsSend = $mailTemplateService->sendEmail($this->settings['mail']['test']['subject'], TRUE);
}
if ($mailIsSend) {
......
......@@ -194,9 +194,10 @@ class MailTemplateService {
* Send the Email
*
* @param string $subject
* @param boolean $isPreview
* @return boolean email was sent or added to mail queue successfully?
*/
public function sendEmail($subject = '') {
public function sendEmail($subject = '', $isPreview = FALSE) {
/** @var Template $template */
$template = $this->templateRepository->findTemplate(
......@@ -216,6 +217,15 @@ class MailTemplateService {
}
}
if ($isPreview) {
$previewMarker = [];
$markerArray = self::$registerArray[$this->extensionKey][$this->templateName]['marker'];
foreach ($markerArray as $marker) {
$previewMarker[$marker['marker']] = $marker['value'];
}
$this->setMarkers($previewMarker);
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var StandaloneView $emailView */
$emailView = $objectManager->get(StandaloneView::class);
......@@ -245,58 +255,6 @@ class MailTemplateService {
return TRUE;
}
/**
* @param string $subject
* @return boolean
*/
public function sendPreviewMail($subject = '') {
/** @var Template $template */
$template = $this->templateRepository->findTemplate(
$this->extensionKey, $this->templateName, $this->language
)->getFirst();
// If there is no template for this language, use the default template
if ($template === NULL) {
$templatePath = self::$registerArray[$this->extensionKey][$this->templateName]['templatePath'];
$templateFile = $templatePath . $this->language . '.template.html';
if (file_exists($templateFile)) {
$defaultTemplateContent = file_get_contents($templatePath . $this->language . '.template.html');
}
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var StandaloneView $emailView */
$emailView = $objectManager->get(StandaloneView::class);
$previewMarker = [];
$markerArray = self::$registerArray[$this->extensionKey][$this->templateName]['marker'];
foreach ($markerArray as $marker) {
$previewMarker[$marker['marker']] = $marker['value'];
}
$this->setMarkers($previewMarker);
if (!isset($defaultTemplateContent)) {
$emailView->setTemplateSource($template->getContent());
$this->mailMessage->setSubject($template->getSubject());
} else {
$emailView->setTemplateSource($defaultTemplateContent);
$this->mailMessage->setSubject($subject);
}
$emailView->assignMultiple($this->markers);
$emailBody = $emailView->render();
// insert <br /> tags, but replace every instance of three or more successive breaks with just two.
$emailBody = nl2br($emailBody);
$emailBody = preg_replace('/(<br[\s]?[\/]?>[\s]*){3,}/', '<br /><br />', $emailBody);
$this->mailMessage->setBody($emailBody, 'text/html');
$this->mailMessage->send();
return TRUE;
}
/**
* Adds a new mail to the mail queue.
*
......
......@@ -35,8 +35,6 @@
<f:form.hidden name="selectedExtensionKey" value="{selectedTemplate.extension}"></f:form.hidden>
<f:form.hidden name="selectedExtension" value="{selectedTemplate.extension}"></f:form.hidden>
<f:form.hidden name="selectedTemplateKey" value="{selectedTemplateKey}"></f:form.hidden>
<f:form.hidden name="contentRight" value="{contentRight}"></f:form.hidden>
<f:form.hidden name="contentLeft" value="{contentLeft}"></f:form.hidden>
</f:form>
<f:form method="post" controller="Mail" action="save">
<div class="col-md-6">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment