Commit 7adf9692 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Review & some refactorings

parent 381cf3e0
......@@ -52,6 +52,8 @@ class SendMailCommandController extends CommandController {
*
* @param int $sendCount
* @return void
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
public function runSendMailsCommand($sendCount = 50) {
$mailsToSend = $this->mailRepository->findMailsToSend($sendCount);
......@@ -65,7 +67,9 @@ class SendMailCommandController extends CommandController {
$mailSubject = $mailToSend->getMailSubject();
$mailBody = $mailToSend->getMailBody();
$mailToSend->setSent(TRUE);
$mailToSend->setSendingTime(time());
$mailToSend->setLastSendingTime(time());
$this->mailRepository->update($mailToSend);
if (empty($fromAddress) || empty($toAddress) || empty($mailSubject)) {
continue;
......
......@@ -75,6 +75,8 @@ class MailController extends ActionController {
* @throws \UnexpectedValueException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function indexAction(array $parameters = []) {
$pid = (int) GeneralUtility::_GP('id');
......@@ -215,9 +217,11 @@ class MailController extends ActionController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function sendTestMailAction(array $parameters = []) {
foreach ($parameters['templates'] as $parameter) {
foreach ((array) $parameters['templates'] as $parameter) {
$ccAddresses = GeneralUtility::trimExplode(',', $parameter['cc']);
if (count($ccAddresses) > 0) {
......@@ -246,7 +250,7 @@ class MailController extends ActionController {
}
}
foreach ($parameters['templates'] as $key => $template) {
foreach ((array) $parameters['templates'] as $key => $template) {
BackendService::saveTemplate(
(int) GeneralUtility::_GP('id'), $parameters['selectedExtension'], $parameters['selectedTemplate'],
$key, $template
......@@ -268,7 +272,7 @@ class MailController extends ActionController {
);
$mailIsSend = FALSE;
foreach ($parameters['templates'] as $key => $template) {
foreach ((array) $parameters['templates'] as $key => $template) {
$mailTemplateService->setLanguage($key);
$mailTemplateService->setToAddresses($parameters['emailAddress']);
$mailTemplateService->setFromAddress($template['fromMail']);
......
......@@ -65,6 +65,8 @@ class QueueController extends ActionController {
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \BadFunctionCallException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function indexAction($selectedTemplate = NULL, $selectedExtension = NULL, array $filters = []) {
$filterTemplate = $_POST['filterTemplate'];
......
......@@ -289,7 +289,7 @@ class MailTemplateService {
return FALSE;
}
} elseif (filter_var($template->getToAddress(), FILTER_VALIDATE_EMAIL)) {
$this->setToAddresses($template->getToAddress());
$this->setToAddresses(trim($template->getToAddress()));
}
if ($isPreview) {
......@@ -428,7 +428,7 @@ class MailTemplateService {
if ($mailToSend) {
$this->mailMessage->setBody($mailToSend->getMailBody(), 'text/html');
$this->mailMessage->setTo($mailToSend->getToAddress());
$this->mailMessage->setTo(trim($mailToSend->getToAddress()));
$this->mailMessage->setFrom($mailToSend->getFromAddress(), $mailToSend->getFromName());
$this->mailMessage->setSubject($mailToSend->getMailSubject());
......@@ -456,8 +456,9 @@ class MailTemplateService {
* @return MailTemplateService
*/
public function setToAddresses($toAddresses) {
$this->toAddresses = $toAddresses;
$this->mailMessage->setTo($toAddresses);
$toAddresses = preg_replace('~\x{00a0}~siu',' ', $toAddresses);
$this->toAddresses = trim($toAddresses);
$this->mailMessage->setTo(trim($toAddresses));
return $this;
}
......
......@@ -42,7 +42,7 @@ class PhpSession implements SingletonInterface {
*/
public function __construct() {
session_start();
$this->sessionKey = uniqid();
$this->sessionKey = uniqid('sgalinski', TRUE);
}
/**
......
......@@ -17,6 +17,7 @@ It also supports Templates in various languages, which can be managed in the bac
Additionally sg_mail provides a finisher class for the [Formhandler](https://typo3.org/extensions/repository/view/formhandler) extension, making it possible to manage its templates in the backend.
sg_mail ist multi-site and multi-language ready.
## Usage
### Registering your Extension
......@@ -34,31 +35,35 @@ Inside the file you have mandatory and optional settings you can define:
- extension_key
Needed to associate this template with the appropriate extension,
- template_key
A unique identifier of your template.
- description
A short description of your templates usage, displayed in the backend template editor. This should be a **language label**
- subject
The default mail subject used for this Template. Here you can also provide a language label.
- markers
An array of placeholder variables. Are dynamically replaced by the appropriate values. If you don't want any markers, provide an empty array.
An array of placeholder variables. Are dynamically replaced by the appropriate values. If you don't want any markers, provide an empty array.
A marker needs to be structured as follows:
A marker needs to be structured as follows:
- marker
The variables name used in your templates.
- type
Here you can specify the variable type by using one of the constants in the **\SGalinski\SgMail\Service\MailTemplateService** class.
- value
An example value of this marker. Also used for previewing your mails in the backend module.
- marker
The variables name used in your templates.
- type
Here you can specify the variable type by using one of the constants in the **\SGalinski\SgMail\Service\MailTemplateService** class.
- value
An example value of this marker. Also used for previewing your mails in the backend module.
- description
A short text describing the purpose of this marker.
- description
A short text describing the purpose of this marker.
**Optional**
......@@ -147,6 +152,13 @@ Go to your scheduler module in the TYPO3 Backend and setup a scheduled CommandCo
For more information on the TYPO3 scheduler extension read its [manual](https://docs.typo3.org/typo3cms/extensions/scheduler/Index.html).
## Language handling
When you provide no language to the MailService API, the default language of the TYPO3 instance is used.
This happens also if the given iso code of the language is not known (inside the **sys_lang** table).
In your template editor you have automatically all languages of your page shown.
## Using sg_mail with Formhandler
In your **setup.txt** of your formhandler extension, you have to invoke the **FormhandlerFinisherService** of sg_mail.
......@@ -198,6 +210,7 @@ With the **Mail Queue** mode, you can see the current content of your mailing qu
<br>
<img height="20px" width="20px" src="https://camo.githubusercontent.com/4b1188209e740e17a4ec0cd6583425696809017b/68747470733a2f2f7261776769742e636f6d2f5459504f332f5459504f332e49636f6e732f6d61737465722f646973742f616374696f6e732f616374696f6e732d646f63756d656e742d766965772e737667"> View the content of this mail
Additionally you can now filter the mail queue or export it to a csv file.
## Developer Guide
......
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