[!!!][BUGFIX] Workspace state change notification email is always in English
authorXavier Perseguers <xavier@typo3.org>
Thu, 3 May 2012 09:17:28 +0000 (11:17 +0200)
committerXavier Perseguers <xavier@typo3.org>
Thu, 14 Jun 2012 06:32:57 +0000 (08:32 +0200)
The preferred language of the recipient is not taken into account which
bypasses the code used to notify user with a localized message in the
past. The end effect is that all notification messages are sent in
English.

Change-Id: I433a744bb377590de444ac8cf960ccfd0b1430db
Depends: I39b23787e6123cfafbd0586952412c029b475b6a
Fixes: #25434
Releases: 4.5, 4.6, 4.7, 6.0
Reviewed-on: http://review.typo3.org/10947
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/workspaces/Classes/ExtDirect/ActionHandler.php

index 5084d22..02d06a2 100644 (file)
@@ -230,9 +230,13 @@ class Tx_Workspaces_ExtDirect_ActionHandler extends Tx_Workspaces_ExtDirect_Abst
                }
                $recipients = array();
                foreach ($uidOfRecipients as $userUid) {
-                       $beUserRecord = t3lib_befunc::getRecord('be_users',intval($userUid));
-                       if (is_array($beUserRecord) && $beUserRecord['email'] != '') {
-                               $recipients[] = $beUserRecord['email'];
+                       $beUserRecord = t3lib_befunc::getRecord('be_users', intval($userUid));
+                       if (is_array($beUserRecord) && $beUserRecord['email'] !== '') {
+                               $uc = $beUserRecord['uc'] ? unserialize($beUserRecord['uc']) : array();
+                               $recipients[$beUserRecord['email']] = array(
+                                       'email' => $beUserRecord['email'],
+                                       'lang'  => (isset($uc['lang']) ? $uc['lang'] : $beUserRecord['lang']),
+                               );
                        }
                }
 
@@ -243,25 +247,35 @@ class Tx_Workspaces_ExtDirect_ActionHandler extends Tx_Workspaces_ExtDirect_Abst
                                // the default recipients needs to be added in some cases of the notification_mode
                        $default_recipients = $this->getStageService()->getResponsibleBeUser($stageId, TRUE);
                        foreach ($default_recipients as $default_recipient_uid => $default_recipient_record) {
-                               if (!in_array($default_recipient_record['email'],$recipients)) {
-                                       $recipients[] = $default_recipient_record['email'];
+                               if (!isset($recipients[$default_recipient_record['email']])) {
+                                       $uc = $default_recipient_record['uc'] ? unserialize($default_recipient_record['uc']) : array();
+                                       $recipients[$default_recipient_record['email']] = array(
+                                               'email' => $default_recipient_record['email'],
+                                               'lang'  => (isset($uc['lang']) ? $uc['lang'] : $default_recipient_record['lang']),
+                                       );
                                }
                        }
                }
 
-               if ($additionalRecipients != '') {
-                       $additionalRecipients = t3lib_div::trimExplode("\n", $additionalRecipients, TRUE);
+               if ($additionalRecipients !== '') {
+                       $emails = t3lib_div::trimExplode(LF, $additionalRecipients, TRUE);
+                       $additionalRecipients = array();
+                       foreach ($emails as $email) {
+                               $additionalRecipients[$email] = array('email' => $email);
+                       };
                } else {
                        $additionalRecipients = array();
                }
 
-               $allRecipients = array_unique(
-                       array_merge($recipients, $additionalRecipients)
-               );
+                       // We merge $recipients on top of $additionalRecipients because $recipients
+                       // possibly is more complete with a user language. Furthermore, the list of
+                       // recipients is automatically unique since we indexed $additionalRecipients
+                       // and $recipients with the email address
+               $allRecipients = array_merge($additionalRecipients, $recipients);
 
-               foreach ($allRecipients as $recipient) {
-                       if (t3lib_div::validEmail($recipient)) {
-                               $finalRecipients[] = $recipient;
+               foreach ($allRecipients as $email => $recipientInformation) {
+                       if (t3lib_div::validEmail($email)) {
+                               $finalRecipients[] = $recipientInformation;
                        }
                }
 
@@ -383,7 +397,6 @@ class Tx_Workspaces_ExtDirect_ActionHandler extends Tx_Workspaces_ExtDirect_Abst
         */
        public function sendToNextStageExecute(stdClass $parameters) {
                $cmdArray = array();
-               $recipients = array();
 
                $setStageId = $parameters->affects->nextStage;
                $comments = $parameters->comments;