ActionMapping - Rename ambiguous 'getEntity' function
authorcolemanw <coleman@civicrm.org>
Sun, 16 Jul 2023 21:29:49 +0000 (17:29 -0400)
committercolemanw <coleman@civicrm.org>
Sun, 16 Jul 2023 22:00:25 +0000 (18:00 -0400)
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
CRM/Contribute/ActionMapping/ByPage.php
CRM/Contribute/ActionMapping/ByType.php
CRM/Core/BAO/ActionSchedule.php
CRM/Core/EntityTokens.php
CRM/Core/TokenTrait.php
CRM/Event/ParticipantTokens.php
Civi/ActionSchedule/Mapping.php
Civi/ActionSchedule/MappingInterface.php
Civi/ActionSchedule/RecipientBuilder.php

index 5f18d8f98fe8527dff63b5219247fab647ab4be5..79ff0ff0ada48b17c7cebe584e2df81cf4fb7fd6 100644 (file)
@@ -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;
     }
 
index 6dcab6e2a7aeb77f9d88a784731f18b69160c3a9..b975b8098dd58e6eedd342cee4e263586f2bf1c3 100644 (file)
@@ -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.
    *
index 88d60e49c767eb078edb1e8b9f2e70bf9120ccac..688f8c753a67d3175b291828fcf1800ad1e62248 100644 (file)
@@ -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.
    *
index d22b86c2c2675e35937059bc34800e320254d4cf..74ded9e794b97731b7807e5c4dd15f6c504bc95b 100644 (file)
@@ -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)',
       ]);
 
index bf94a19d049930f75bc65e25a2b905655b7b9594..aee65f713c9132fa1ca2a99e7844eeba80263b27 100644 (file)
@@ -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());
index 36c6829bb826b5239b60a6e4b27bb60ae8289b36..0603eb92b6f15b9cd368dfa91d5592ffad1a56c8 100644 (file)
@@ -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());
   }
 
   /**
index 8fb62af630ef7e9ac80b82893720200e952e6885..6df913b0ac2f5e508f66f175853f77f2180f38fe 100644 (file)
@@ -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');
     }
   }
index 948fcf538978cf88158c73a039dfb283dc9cdfc4..aeea2663eb151cfd6ed9610cfd69786d998805f2 100644 (file)
@@ -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.
    *
index f551fc11c1968a303968e18fd02cd35387252dcf..62e530bf87915dfad2f4f84486111a1693dae8ec 100644 (file)
@@ -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.
index 2366b69fdd06026177f066b0ba79f0ba29421f51..c32820475fc286dbf629e779bd3d7f9793703039 100644 (file)
@@ -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;