From 3fcf0983ae9921ef9c5cce54a2aec76bbe13697f Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 7 Aug 2021 04:08:18 +1200 Subject: [PATCH] [Ref] cleanup alterActionSchedule We can simplify this function now as basicFields is keyed by the real field name and all pseudofields are already in basicFields. --- CRM/Contribute/Tokens.php | 14 ++++---------- CRM/Core/EntityTokens.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/Tokens.php b/CRM/Contribute/Tokens.php index 0cdfc560fc..4f56ab6343 100644 --- a/CRM/Contribute/Tokens.php +++ b/CRM/Contribute/Tokens.php @@ -125,7 +125,7 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens { */ public function checkActive(TokenProcessor $processor) { return !empty($processor->context['actionMapping']) - && $processor->context['actionMapping']->getEntity() === 'civicrm_contribution'; + && $processor->context['actionMapping']->getEntity() === $this->getExtendableTableName(); } /** @@ -134,17 +134,11 @@ class CRM_Contribute_Tokens extends CRM_Core_EntityTokens { * @param \Civi\ActionSchedule\Event\MailingQueryEvent $e */ public function alterActionScheduleQuery(MailingQueryEvent $e): void { - if ($e->mapping->getEntity() !== 'civicrm_contribution') { + if ($e->mapping->getEntity() !== $this->getExtendableTableName()) { return; } - - $fields = $this->getFieldMetadata(); - foreach (array_keys($this->getBasicTokens()) as $token) { - $e->query->select('e.' . $fields[$token]['name'] . ' AS ' . $this->getEntityAlias() . $token); - } - foreach (array_keys($this->getPseudoTokens()) as $token) { - $split = explode(':', $token); - $e->query->select('e.' . $fields[$split[0]]['name'] . ' AS ' . $this->getEntityAlias() . $split[0]); + foreach ($this->getReturnFields() as $token) { + $e->query->select('e.' . $token . ' AS ' . $this->getEntityAlias() . $token); } } diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index bf677ad1f2..5ee445f236 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -54,6 +54,17 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return $this->getApiEntityName() . '__'; } + /** + * Get the name of the table this token class can extend. + * + * The default is based on the entity but some token classes, + * specifically the event class, latch on to other tables - ie + * the participant table. + */ + public function getExtendableTableName(): string { + return CRM_Core_DAO_AllCoreTables::getTableForEntityName($this->getApiEntityName()); + } + /** * Get the relevant bao name. */ @@ -61,6 +72,15 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return CRM_Core_DAO_AllCoreTables::getFullName($this->getApiEntityName()); } + /** + * Get an array of fields to be requested. + * + * @return string[] + */ + public function getReturnFields(): array { + return array_keys($this->getBasicTokens()); + } + /** * Get all the tokens supported by this processor. * -- 2.25.1