From 3b191d7d7a24835a9cd19de49d6577484d5c4182 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 9 Aug 2021 22:59:54 -0700 Subject: [PATCH] (REF) ActionSchedule - Pass through SQL fields named "tokenContext_*" This will help us to consolidate the prefetching logic in `CRM_*_Tokens`. Currently, `CRM_*_Token::alterActionScheduleQuery()` updates the query to select all fields for the entity. This is regardless of how many fields there are, whether they are needed, etc. This is also prone to naming conflicts. With this patch, `CRM_*_Token::alterActionScheduleQuery()` only needs to select one field (`tokenContext_fooId`). This will then propagate to the `TokenProcessor` which can do its own optimized data-loading. --- CRM/Core/BAO/ActionSchedule.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 5821fced06..5b6fbf84cf 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -278,6 +278,15 @@ FROM civicrm_action_schedule cas $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 ($dao->toArray() as $key => $value) { + if (preg_match('/^tokenContext_(.*)/', $key, $m)) { + if (!in_array($m[1], $tokenProcessor->context['schema'])) { + $tokenProcessor->context['schema'][] = $m[1]; + } + $row->context($m[1], $value); + } + } } $tokenProcessor->evaluate(); -- 2.25.1