From 9ae8e0ffd7804b1e7f52b6955dbc954e1b57ea42 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 10 Aug 2021 18:13:48 -0700 Subject: [PATCH] CRM_Activity_Tokens - Simplify prefetch. Remove special-cases for `actionSearchResult`. Before: There are two distinct ways in which `CRM_Activity_Tokens` can be called, eg * For scheduled reminders, it's given `$row->context[actionSearchResult]`. The query is inspected for data. * For everything else, it's given `$row->context[activityId]`. The value is After: `CRM_Activity_Tokens` always receives activities as `$row->context[activityId]`. Comment: There are pre-existing tests for activity-based reminders and tokens in `CRM_Core_BAO_ActionScheduleTest` and `CRM_Activity_ActionMappingTest`. --- CRM/Activity/Tokens.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CRM/Activity/Tokens.php b/CRM/Activity/Tokens.php index 66663dd7c4..bfcb4e76e5 100644 --- a/CRM/Activity/Tokens.php +++ b/CRM/Activity/Tokens.php @@ -84,6 +84,7 @@ class CRM_Activity_Tokens extends AbstractTokenSubscriber { // Multiple revisions of the activity. // Q: Could we simplify & move the extra AND clauses into `where(...)`? $e->query->param('casEntityJoinExpr', 'e.id = reminder.entity_id AND e.is_current_revision = 1 AND e.is_deleted = 0'); + $e->query->select('e.id AS tokenContext_' . $this->getEntityContextSchema()); } /** @@ -91,9 +92,7 @@ class CRM_Activity_Tokens extends AbstractTokenSubscriber { */ public function prefetch(TokenValueEvent $e) { // Find all the entity IDs - $entityIds - = $e->getTokenProcessor()->getContextValues('actionSearchResult', 'entityID') - + $e->getTokenProcessor()->getContextValues($this->getEntityContextSchema()); + $entityIds = $e->getTokenProcessor()->getContextValues($this->getEntityContextSchema()); if (!$entityIds) { return NULL; @@ -144,8 +143,7 @@ class CRM_Activity_Tokens extends AbstractTokenSubscriber { 'activity_id' => 'id', ]; - // Get ActivityID either from actionSearchResult (for scheduled reminders) if exists - $activityId = $row->context['actionSearchResult']->entityID ?? $row->context[$this->getEntityContextSchema()]; + $activityId = $row->context[$this->getEntityContextSchema()]; $activity = $prefetch['activity'][$activityId]; -- 2.25.1