From: Tim Otten Date: Tue, 10 Aug 2021 04:13:57 +0000 (-0700) Subject: ActionSchedule - Convert from global `setLocale()` to `$context['locale']` X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f14b9b1bb012d93609404e63f3c61c1be56ec671;p=civicrm-core.git ActionSchedule - Convert from global `setLocale()` to `$context['locale']` Before: Runs `setLocale()` and then executes the entire pipeline for `TokenProcessor` After: Leaves the global locale alone. Instead, rely on `TokenProcessor` to switch locale as it visits each recipient. --- diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index abcd747f44..00ac176a98 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -268,18 +268,19 @@ FROM civicrm_action_schedule cas $multilingual = CRM_Core_I18n::isMultilingual(); while ($dao->fetch()) { - // switch language if necessary - if ($multilingual) { - $preferred_language = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contactID, 'preferred_language'); - CRM_Core_I18n::singleton()->setLocale(CRM_Core_BAO_ActionSchedule::pickLocale($actionSchedule->communication_language, $preferred_language)); - } - $errors = []; try { $tokenProcessor = self::createTokenProcessor($actionSchedule, $mapping); - $tokenProcessor->addRow() + $row = $tokenProcessor->addRow() ->context('contactId', $dao->contactID) ->context('actionSearchResult', (object) $dao->toArray()); + + // switch language if necessary + if ($multilingual) { + $preferred_language = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $dao->contactID, 'preferred_language'); + $row->context('locale', CRM_Core_BAO_ActionSchedule::pickLocale($actionSchedule->communication_language, $preferred_language)); + } + foreach ($tokenProcessor->evaluate()->getRows() as $tokenRow) { if ($actionSchedule->mode === 'SMS' || $actionSchedule->mode === 'User_Preference') { CRM_Utils_Array::extend($errors, self::sendReminderSms($tokenRow, $actionSchedule, $dao->contactID));