From 25f871c96b7a70a2bf03eb276405f29ab548ca80 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sun, 16 Jul 2023 17:29:49 -0400 Subject: [PATCH] ActionMapping - Rename ambiguous 'getEntity' function Before: function getEntity() actually returns the name of the table, not the entity After: function getEntityTable() returns table name and getEntityName() returns entity name --- CRM/Activity/Tokens.php | 2 +- CRM/Contribute/ActionMapping/ByPage.php | 6 +++++- CRM/Contribute/ActionMapping/ByType.php | 9 ++++++++- CRM/Core/BAO/ActionSchedule.php | 4 ++-- CRM/Core/EntityTokens.php | 4 ++-- CRM/Core/TokenTrait.php | 2 +- CRM/Event/ParticipantTokens.php | 2 +- Civi/ActionSchedule/Mapping.php | 6 +++++- Civi/ActionSchedule/MappingInterface.php | 9 ++++++++- Civi/ActionSchedule/RecipientBuilder.php | 10 +++++----- 10 files changed, 38 insertions(+), 16 deletions(-) diff --git a/CRM/Activity/Tokens.php b/CRM/Activity/Tokens.php index 5f18d8f98f..79ff0ff0ad 100644 --- a/CRM/Activity/Tokens.php +++ b/CRM/Activity/Tokens.php @@ -37,7 +37,7 @@ class CRM_Activity_Tokens extends CRM_Core_EntityTokens { * @inheritDoc */ public function alterActionScheduleQuery(MailingQueryEvent $e): void { - if ($e->mapping->getEntity() !== $this->getExtendableTableName()) { + if ($e->mapping->getEntityTable() !== $this->getExtendableTableName()) { return; } diff --git a/CRM/Contribute/ActionMapping/ByPage.php b/CRM/Contribute/ActionMapping/ByPage.php index 6dcab6e2a7..b975b8098d 100644 --- a/CRM/Contribute/ActionMapping/ByPage.php +++ b/CRM/Contribute/ActionMapping/ByPage.php @@ -45,10 +45,14 @@ class CRM_Contribute_ActionMapping_ByPage implements \Civi\ActionSchedule\Mappin /** * @return string */ - public function getEntity() { + public function getEntityTable(): string { return 'civicrm_contribution'; } + public function getEntityName(): string { + return 'Contribution'; + } + /** * Get a printable label for this mapping type. * diff --git a/CRM/Contribute/ActionMapping/ByType.php b/CRM/Contribute/ActionMapping/ByType.php index 88d60e49c7..688f8c753a 100644 --- a/CRM/Contribute/ActionMapping/ByType.php +++ b/CRM/Contribute/ActionMapping/ByType.php @@ -45,10 +45,17 @@ class CRM_Contribute_ActionMapping_ByType implements \Civi\ActionSchedule\Mappin /** * @return string */ - public function getEntity() { + public function getEntityTable(): string { return 'civicrm_contribution'; } + /** + * @return string + */ + public function getEntityName(): string { + return 'Contribution'; + } + /** * Get a printable label for this mapping type. * diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index d22b86c2c2..74ded9e794 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -442,7 +442,7 @@ FROM civicrm_action_schedule cas protected static function createMailingActivity($tokenRow, $mapping, $contactID, $entityID, $caseID) { $session = CRM_Core_Session::singleton(); - if ($mapping->getEntity() == 'civicrm_membership') { + if ($mapping->getEntityTable() == 'civicrm_membership') { // @todo - not required with api $activityTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Membership Renewal Reminder'); @@ -487,7 +487,7 @@ FROM civicrm_action_schedule cas 'casActionScheduleId' => $actionSchedule->id, 'casMailingJoinType' => ($actionSchedule->limit_to == 0) ? 'LEFT JOIN' : 'INNER JOIN', 'casMappingId' => $mapping->getId(), - 'casMappingEntity' => $mapping->getEntity(), + 'casMappingEntity' => $mapping->getEntityTable(), 'casEntityJoinExpr' => 'e.id = IF(reminder.entity_table = "civicrm_contact", reminder.contact_id, reminder.entity_id)', ]); diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index bf94a19d04..aee65f713c 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -351,7 +351,7 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { return (!empty($processor->context['actionMapping']) // This makes the 'schema context compulsory - which feels accidental // since recent discu - && $processor->context['actionMapping']->getEntity()) || in_array($this->getEntityIDField(), $processor->context['schema']); + && $processor->context['actionMapping']->getEntityTable()) || in_array($this->getEntityIDField(), $processor->context['schema']); } /** @@ -360,7 +360,7 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { * @param \Civi\ActionSchedule\Event\MailingQueryEvent $e */ public function alterActionScheduleQuery(MailingQueryEvent $e): void { - if ($e->mapping->getEntity() !== $this->getExtendableTableName()) { + if ($e->mapping->getEntityTable() !== $this->getExtendableTableName()) { return; } $e->query->select('e.id AS tokenContext_' . $this->getEntityIDField()); diff --git a/CRM/Core/TokenTrait.php b/CRM/Core/TokenTrait.php index 36c6829bb8..0603eb92b6 100644 --- a/CRM/Core/TokenTrait.php +++ b/CRM/Core/TokenTrait.php @@ -28,7 +28,7 @@ trait CRM_Core_TokenTrait { public function checkActive(TokenProcessor $processor) { return in_array($this->getEntityContextSchema(), $processor->context['schema']) || (!empty($processor->context['actionMapping']) - && $processor->context['actionMapping']->getEntity() === $this->getEntityTableName()); + && $processor->context['actionMapping']->getEntityTable() === $this->getEntityTableName()); } /** diff --git a/CRM/Event/ParticipantTokens.php b/CRM/Event/ParticipantTokens.php index 8fb62af630..6df913b0ac 100644 --- a/CRM/Event/ParticipantTokens.php +++ b/CRM/Event/ParticipantTokens.php @@ -54,7 +54,7 @@ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent $e): void { // When targeting `civicrm_participant` records, we enable both `{participant.*}` (per usual) and the related `{event.*}`. parent::alterActionScheduleQuery($e); - if ($e->mapping->getEntity() === $this->getExtendableTableName()) { + if ($e->mapping->getEntityTable() === $this->getExtendableTableName()) { $e->query->select('e.event_id AS tokenContext_eventId'); } } diff --git a/Civi/ActionSchedule/Mapping.php b/Civi/ActionSchedule/Mapping.php index 948fcf5389..aeea2663eb 100644 --- a/Civi/ActionSchedule/Mapping.php +++ b/Civi/ActionSchedule/Mapping.php @@ -156,10 +156,14 @@ abstract class Mapping implements MappingInterface { /** * @return string */ - public function getEntity() { + public function getEntityTable(): string { return $this->entity; } + public function getEntityName(): string { + return \CRM_Core_DAO_AllCoreTables::getEntityNameForTable($this->getEntityTable()); + } + /** * Get a printable label for this mapping type. * diff --git a/Civi/ActionSchedule/MappingInterface.php b/Civi/ActionSchedule/MappingInterface.php index f551fc11c1..62e530bf87 100644 --- a/Civi/ActionSchedule/MappingInterface.php +++ b/Civi/ActionSchedule/MappingInterface.php @@ -23,9 +23,16 @@ interface MappingInterface { public function getId(); /** + * Name of the table belonging to the main entity e.g. `civicrm_activity` * @return string */ - public function getEntity(); + public function getEntityTable(): string; + + /** + * Main entity name e.g. `Activity` + * @return string + */ + public function getEntityName(): string; /** * Get a printable label for this mapping type. diff --git a/Civi/ActionSchedule/RecipientBuilder.php b/Civi/ActionSchedule/RecipientBuilder.php index 2366b69fdd..c32820475f 100644 --- a/Civi/ActionSchedule/RecipientBuilder.php +++ b/Civi/ActionSchedule/RecipientBuilder.php @@ -190,9 +190,9 @@ class RecipientBuilder { ->merge($this->prepareAddlFilter('c.id')) ->where("c.id NOT IN ( SELECT rem.contact_id - FROM civicrm_action_log rem INNER JOIN {$this->mapping->getEntity()} e ON rem.entity_id = e.id + FROM civicrm_action_log rem INNER JOIN {$this->mapping->getEntityTable()} e ON rem.entity_id = e.id WHERE rem.action_schedule_id = {$this->actionSchedule->id} - AND rem.entity_table = '{$this->mapping->getEntity()}' + AND rem.entity_table = '{$this->mapping->getEntityTable()}' )") // Where does e.id come from here? ^^^ ->groupBy("c.id") @@ -276,7 +276,7 @@ class RecipientBuilder { $defaultParams = [ 'casActionScheduleId' => $this->actionSchedule->id, 'casMappingId' => $this->mapping->getId(), - 'casMappingEntity' => $this->mapping->getEntity(), + 'casMappingEntity' => $this->mapping->getEntityTable(), 'casNow' => $this->now, ]; @@ -403,7 +403,7 @@ class RecipientBuilder { $date = $operator . "(!casDateField, INTERVAL {$actionSchedule->start_action_offset} {$actionSchedule->start_action_unit})"; $startDateClauses[] = "'!casNow' >= {$date}"; // This is weird. Waddupwidat? - if ($this->mapping->getEntity() == 'civicrm_participant') { + if ($this->mapping->getEntityTable() == 'civicrm_participant') { $startDateClauses[] = $operator . "(!casNow, INTERVAL 1 DAY ) {$op} " . '!casDateField'; } else { @@ -567,7 +567,7 @@ WHERE $group.id = {$groupId} switch ($for) { case 'rel': $contactIdField = $query['casContactIdField']; - $entityName = $this->mapping->getEntity(); + $entityName = $this->mapping->getEntityTable(); $entityIdField = $query['casEntityIdField']; break; -- 2.25.1