From 39eb69ec7d483b7d10abffb6ebd679d66d6b8446 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 10 Aug 2021 17:11:00 -0700 Subject: [PATCH] (REF) ActionSchedule - Remove unused `try`/`catch(TokenException $e)` This try/catch block purports to catch any exceptions of type `TokenException`. However, if you grep the source tree, you will find that `TokenException` is never thrown. --- CRM/Core/BAO/ActionSchedule.php | 55 +++++++++++++++------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index d77feae933..014978230e 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -269,40 +269,35 @@ FROM civicrm_action_schedule cas $multilingual = CRM_Core_I18n::isMultilingual(); while ($dao->fetch()) { $errors = []; - try { - $tokenProcessor = self::createTokenProcessor($actionSchedule, $mapping); - $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) { - // It's possible, eg, that sendReminderEmail fires Hook::alterMailParams() and that some listener use ts(). - $swapLocale = empty($row->context['locale']) ? NULL : \CRM_Utils_AutoClean::swapLocale($row->context['locale']); + $tokenProcessor = self::createTokenProcessor($actionSchedule, $mapping); + $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)); + } - if ($actionSchedule->mode === 'SMS' || $actionSchedule->mode === 'User_Preference') { - CRM_Utils_Array::extend($errors, self::sendReminderSms($tokenRow, $actionSchedule, $dao->contactID)); - } + foreach ($tokenProcessor->evaluate()->getRows() as $tokenRow) { + // It's possible, eg, that sendReminderEmail fires Hook::alterMailParams() and that some listener use ts(). + $swapLocale = empty($row->context['locale']) ? NULL : \CRM_Utils_AutoClean::swapLocale($row->context['locale']); - if ($actionSchedule->mode === 'Email' || $actionSchedule->mode === 'User_Preference') { - CRM_Utils_Array::extend($errors, self::sendReminderEmail($tokenRow, $actionSchedule, $dao->contactID)); - } - // insert activity log record if needed - if ($actionSchedule->record_activity && empty($errors)) { - $caseID = empty($dao->case_id) ? NULL : $dao->case_id; - CRM_Core_BAO_ActionSchedule::createMailingActivity($tokenRow, $mapping, $dao->contactID, $dao->entityID, $caseID); - } + if ($actionSchedule->mode === 'SMS' || $actionSchedule->mode === 'User_Preference') { + CRM_Utils_Array::extend($errors, self::sendReminderSms($tokenRow, $actionSchedule, $dao->contactID)); + } - unset($swapLocale); + if ($actionSchedule->mode === 'Email' || $actionSchedule->mode === 'User_Preference') { + CRM_Utils_Array::extend($errors, self::sendReminderEmail($tokenRow, $actionSchedule, $dao->contactID)); } - } - catch (\Civi\Token\TokenException $e) { - $errors['token_exception'] = $e->getMessage(); + // insert activity log record if needed + if ($actionSchedule->record_activity && empty($errors)) { + $caseID = empty($dao->case_id) ? NULL : $dao->case_id; + CRM_Core_BAO_ActionSchedule::createMailingActivity($tokenRow, $mapping, $dao->contactID, $dao->entityID, $caseID); + } + + unset($swapLocale); } // update action log record -- 2.25.1