(REF) ActionSchedule - Remove unused `try`/`catch(TokenException $e)`
authorTim Otten <totten@civicrm.org>
Wed, 11 Aug 2021 00:11:00 +0000 (17:11 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 11 Aug 2021 01:57:05 +0000 (18:57 -0700)
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

index d77feae9331b3ec46c1841dc6568d7f74388202b..014978230e83c6046649024456a0a3a206005c63 100644 (file)
@@ -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