[FEATURE] Enable multiple emails in reports task 19/18019/7
authorThomas Löffler <loeffler@spooner-web.de>
Tue, 5 Feb 2013 00:05:38 +0000 (01:05 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 7 Feb 2013 21:19:39 +0000 (22:19 +0100)
Possibility to insert multiple emails in
reports task to notify multiple people.

Resolves: #41002
Releases: 6.1
Change-Id: I931cd5af64d21bffb34bd024c1f362f06dcaf37c
Reviewed-on: https://review.typo3.org/18019
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Tomita Militaru
Tested-by: Tomita Militaru
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/reports/Classes/Task/SystemStatusUpdateTask.php
typo3/sysext/reports/Classes/Task/SystemStatusUpdateTaskNotificationEmailField.php
typo3/sysext/reports/reports/locallang.xlf

index c805f3d..eeafb28 100644 (file)
@@ -31,7 +31,7 @@ namespace TYPO3\CMS\Reports\Task;
 class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
 
        /**
 class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
 
        /**
-        * Email address to send email notification to in case we find problems with
+        * Email addresses to send email notification to in case we find problems with
         * the system.
         *
         * @var string
         * the system.
         *
         * @var string
@@ -43,7 +43,7 @@ class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
         * status reports and saving that to the registry to be displayed at login
         * if necessary.
         *
         * status reports and saving that to the registry to be displayed at login
         * if necessary.
         *
-        * @see typo3/sysext/scheduler/tx_scheduler_Task::execute()
+        * @see \TYPO3\CMS\Scheduler\Task\AbstractTask::execute()
         */
        public function execute() {
                /** @var $registry \TYPO3\CMS\Core\Registry */
         */
        public function execute() {
                /** @var $registry \TYPO3\CMS\Core\Registry */
@@ -60,9 +60,9 @@ class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
        }
 
        /**
        }
 
        /**
-        * Gets the notification email address.
+        * Gets the notification email addresses.
         *
         *
-        * @return string Notification email address.
+        * @return string Notification email addresses.
         */
        public function getNotificationEmail() {
                return $this->notificationEmail;
         */
        public function getNotificationEmail() {
                return $this->notificationEmail;
@@ -93,6 +93,11 @@ class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
                                }
                        }
                }
                                }
                        }
                }
+               $notificationEmails = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $this->notificationEmail, TRUE);
+               $sendEmailsTo = array();
+               foreach ($notificationEmails as $notificationEmail) {
+                       $sendEmailsTo[] = $notificationEmail;
+               }
                $subject = sprintf($GLOBALS['LANG']->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
                $message = sprintf($GLOBALS['LANG']->getLL('status_problemNotification'), '', '');
                $message .= CRLF . CRLF;
                $subject = sprintf($GLOBALS['LANG']->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
                $message = sprintf($GLOBALS['LANG']->getLL('status_problemNotification'), '', '');
                $message .= CRLF . CRLF;
@@ -102,9 +107,10 @@ class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
                $message .= implode(CRLF, $systemIssues);
                $message .= CRLF . CRLF;
                $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
                $message .= implode(CRLF, $systemIssues);
                $message .= CRLF . CRLF;
                $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
+               /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
                $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
                $mail->setFrom($from);
                $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
                $mail->setFrom($from);
-               $mail->setTo($this->notificationEmail);
+               $mail->setTo($sendEmailsTo);
                $mail->setSubject($subject);
                $mail->setBody($message);
                $mail->send();
                $mail->setSubject($subject);
                $mail->setBody($message);
                $mail->send();
@@ -112,5 +118,4 @@ class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
 
 }
 
 
 }
 
-
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file
index e0400f7..0426c2c 100644 (file)
@@ -54,22 +54,23 @@ class SystemStatusUpdateTaskNotificationEmailField implements \TYPO3\CMS\Schedul
         * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
         */
        public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
         * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
         */
        public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
-               $fields = array('notificationEmail');
+               $fields = array('notificationEmail' => 'textarea');
                if ($schedulerModule->CMD == 'edit') {
                        $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
                }
                if ($schedulerModule->CMD == 'edit') {
                        $taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
                }
+                       // build html for additional email field
+               $fieldName = $this->getFullFieldName('notificationEmail');
+               $fieldId = 'task_' . $fieldName;
+               $fieldHtml = '<textarea ' . 'rows="5" cols="50" name="tx_scheduler[' . $fieldName . ']" ' . 'id="' . $fieldId . '" ' . '>' . htmlspecialchars($taskInfo[$fieldName]) . '</textarea>';
+
                $additionalFields = array();
                $additionalFields = array();
-               foreach ($fields as $field) {
-                       $fieldName = $this->getFullFieldName($field);
-                       $fieldId = 'task_' . $fieldName;
-                       $fieldHtml = '<input type="text" ' . 'name="tx_scheduler[' . $fieldName . ']" ' . 'id="' . $fieldId . '" ' . 'value="' . htmlspecialchars($taskInfo[$fieldName]) . '" />';
-                       $additionalFields[$fieldId] = array(
-                               'code' => $fieldHtml,
-                               'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_' . $field,
-                               'cshKey' => '',
-                               'cshLabel' => $fieldId
-                       );
-               }
+               $additionalFields[$fieldId] = array(
+                       'code' => $fieldHtml,
+                       'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmails',
+                       'cshKey' => '',
+                       'cshLabel' => $fieldId
+               );
+
                return $additionalFields;
        }
 
                return $additionalFields;
        }
 
@@ -82,9 +83,15 @@ class SystemStatusUpdateTaskNotificationEmailField implements \TYPO3\CMS\Schedul
         */
        public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
                $validInput = TRUE;
         */
        public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
                $validInput = TRUE;
-               $submittedData[$this->fieldPrefix . 'NotificationEmail'] = trim($submittedData[$this->fieldPrefix . 'NotificationEmail']);
-               if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !filter_var($submittedData[($this->fieldPrefix . 'NotificationEmail')], FILTER_VALIDATE_EMAIL)) {
-                       $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmail_invalid'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+               $notificationEmails = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], TRUE);
+               foreach ($notificationEmails as $notificationEmail) {
+                       if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($notificationEmail)) {
+                               $validInput = FALSE;
+                               break;
+                       }
+               }
+               if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !$validInput) {
+                       $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmails_invalid'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
                        $validInput = FALSE;
                }
                return $validInput;
                        $validInput = FALSE;
                }
                return $validInput;
@@ -116,5 +123,4 @@ class SystemStatusUpdateTaskNotificationEmailField implements \TYPO3\CMS\Schedul
 
 }
 
 
 }
 
-
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file
index 796bf56..76f850e 100644 (file)
@@ -234,9 +234,15 @@ You can increase the size to 8MB (default on unix) by adding to the httpd.conf:
                        <trans-unit id="status_updateTaskField_notificationEmail" xml:space="preserve">
                                <source>Notification Email Address</source>
                        </trans-unit>
                        <trans-unit id="status_updateTaskField_notificationEmail" xml:space="preserve">
                                <source>Notification Email Address</source>
                        </trans-unit>
+                       <trans-unit id="status_updateTaskField_notificationEmails" xml:space="preserve">
+                               <source>Notification Email Addresses (one per line)</source>
+                       </trans-unit>
                        <trans-unit id="status_updateTaskField_notificationEmail_invalid" xml:space="preserve">
                                <source>Empty or invalid notification email address.</source>
                        </trans-unit>
                        <trans-unit id="status_updateTaskField_notificationEmail_invalid" xml:space="preserve">
                                <source>Empty or invalid notification email address.</source>
                        </trans-unit>
+                       <trans-unit id="status_updateTaskField_notificationEmails_invalid" xml:space="preserve">
+                               <source>Empty or invalid notification email addresses.</source>
+                       </trans-unit>
                        <trans-unit id="status_updateTask_email_subject" xml:space="preserve">
                                <source>System Status Notification for site %s</source>
                        </trans-unit>
                        <trans-unit id="status_updateTask_email_subject" xml:space="preserve">
                                <source>System Status Notification for site %s</source>
                        </trans-unit>