CRM_Utils_Recent - Use hook listener to delete items
authorColeman Watts <coleman@civicrm.org>
Sat, 21 Aug 2021 19:11:37 +0000 (15:11 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 22 Aug 2021 23:28:39 +0000 (19:28 -0400)
dev/core#2757

CRM/Activity/BAO/Activity.php
CRM/Case/BAO/Case.php
CRM/Contact/BAO/Group.php
CRM/Contact/BAO/Relationship.php
CRM/Contribute/BAO/Contribution.php
CRM/Event/BAO/Participant.php
CRM/Grant/BAO/Grant.php
CRM/Member/BAO/Membership.php
CRM/Pledge/BAO/Pledge.php
CRM/Utils/Recent.php
Civi/Core/Container.php

index 922abde2898a6228654b587e21215d8a703c7d15..d60d201b0c12e1ed4ef07fde543a82cfb1eb8f4b 100644 (file)
@@ -217,15 +217,6 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       self::logActivityAction($activity, $logMsg);
     }
 
-    // delete the recently created Activity
-    if ($result) {
-      $activityRecent = [
-        'id' => $activity->id,
-        'type' => 'Activity',
-      ];
-      CRM_Utils_Recent::del($activityRecent);
-    }
-
     $transaction->commit();
     if (isset($activity)) {
       // CRM-8708
index 65846ce83a614558131b6644bb781cccc1572357..5014e4a0cd1e39ba46bd2ecf995df2e809615c8e 100644 (file)
@@ -217,12 +217,6 @@ WHERE civicrm_case.id = %1";
 
       CRM_Utils_Hook::post('delete', 'Case', $caseId, $case);
 
-      // remove case from recent items.
-      $caseRecent = [
-        'id' => $caseId,
-        'type' => 'Case',
-      ];
-      CRM_Utils_Recent::del($caseRecent);
       return TRUE;
     }
 
index 48e5802ab2e5a9e7d47ff3bed32c09535c6d0ace..b9c6be59ea09fb6ba48548d0076885d6c4a786d0 100644 (file)
@@ -116,13 +116,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
     $transaction->commit();
 
     CRM_Utils_Hook::post('delete', 'Group', $id, $group);
-
-    // delete the recently created Group
-    $groupRecent = [
-      'id' => $id,
-      'type' => 'Group',
-    ];
-    CRM_Utils_Recent::del($groupRecent);
   }
 
   /**
index cacd788ac96e0f1b3dcb2401fc57d1a1a85a9b54..c4aa4de85e1ed573fecf3da467b9e773d8b7ef4c 100644 (file)
@@ -744,13 +744,6 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
 
     CRM_Utils_Hook::post('delete', 'Relationship', $id, $relationship);
 
-    // delete the recently created Relationship
-    $relationshipRecent = [
-      'id' => $id,
-      'type' => 'Relationship',
-    ];
-    CRM_Utils_Recent::del($relationshipRecent);
-
     return $relationship;
   }
 
index 10d7689d485b0f9ff807d66a3ea71623e3b666b7..840878bc6cf020c5729ea31c5942a3d764382296 100644 (file)
@@ -1530,13 +1530,6 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = c.contact_id )
 
     CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao);
 
-    // delete the recently created Contribution
-    $contributionRecent = [
-      'id' => $id,
-      'type' => 'Contribution',
-    ];
-    CRM_Utils_Recent::del($contributionRecent);
-
     return $results;
   }
 
index 90b9a2f6aa0409fe082d0564926d5cffaae35861..4d73cf25660d475746d7c3b4f47b1a840f96dd73 100644 (file)
@@ -876,14 +876,6 @@ WHERE  civicrm_participant.id = {$participantId}
 
     CRM_Utils_Hook::post('delete', 'Participant', $participant->id, $participant);
 
-    // delete the recently created Participant
-    $participantRecent = [
-      'id' => $id,
-      'type' => 'Participant',
-    ];
-
-    CRM_Utils_Recent::del($participantRecent);
-
     return $participant;
   }
 
index bc33e04c8070ee600643c5a20239b2c9b24c3b27..c2e4dad3c0a4ca6358bd00292187cc9a61ba98d0 100644 (file)
@@ -259,13 +259,6 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant {
 
     $grant->find();
 
-    // delete the recently created Grant
-    $grantRecent = [
-      'id' => $id,
-      'type' => 'Grant',
-    ];
-    CRM_Utils_Recent::del($grantRecent);
-
     if ($grant->fetch()) {
       $results = $grant->delete();
       CRM_Utils_Hook::post('delete', 'Grant', $grant->id, $grant);
index edc63eda522cba388a9cc6a28ab97fa7890270fa..8e95311d446b1dfe3a4e6c53f9fcdf9506b565a7 100644 (file)
@@ -673,13 +673,6 @@ INNER JOIN  civicrm_membership_type type ON ( type.id = membership.membership_ty
 
     CRM_Utils_Hook::post('delete', 'Membership', $membership->id, $membership);
 
-    // delete the recently created Membership
-    $membershipRecent = [
-      'id' => $membershipId,
-      'type' => 'Membership',
-    ];
-    CRM_Utils_Recent::del($membershipRecent);
-
     return $results;
   }
 
index 63078610fd4893439d0913d378c095c6ed3d9e6a..61f95340bcabed1185ff8e4bf1c321002983b3a0 100644 (file)
@@ -314,13 +314,6 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
 
     CRM_Utils_Hook::post('delete', 'Pledge', $dao->id, $dao);
 
-    // delete the recently created Pledge
-    $pledgeRecent = [
-      'id' => $id,
-      'type' => 'Pledge',
-    ];
-    CRM_Utils_Recent::del($pledgeRecent);
-
     return $results;
   }
 
index 59818c0b0161810545c107cf6937bfc61505a124..231f4af39540be574e3bf4cc1f2a7b856abbcbda 100644 (file)
@@ -136,6 +136,20 @@ class CRM_Utils_Recent {
     $session->set(self::STORE_NAME, self::$_recent);
   }
 
+  /**
+   * Callback for hook_civicrm_post().
+   * @param \Civi\Core\Event\PostEvent $event
+   */
+  public static function on_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) {
+    if ($event->action === 'delete' && $event->id && CRM_Core_Session::getLoggedInContactID()) {
+      // Is this an entity that might be in the recent items list?
+      $providersPermitted = Civi::settings()->get('recentItemsProviders') ?: array_keys(self::getProviders());
+      if (in_array($event->entity, $providersPermitted)) {
+        self::del(['id' => $event->id, 'type' => $event->entity]);
+      }
+    }
+  }
+
   /**
    * Delete an item from the recent stack.
    *
index 72e69c4762d11702877d06615f43156eb48aec0e..c680216844c590b5c8ea76c17a3a94a93bfb6760 100644 (file)
@@ -406,6 +406,8 @@ class Container {
     $dispatcher->addListener('hook_civicrm_coreResourceList', ['\CRM_Utils_System', 'appendCoreResources']);
     $dispatcher->addListener('hook_civicrm_getAssetUrl', ['\CRM_Utils_System', 'alterAssetUrl']);
     $dispatcher->addListener('hook_civicrm_alterExternUrl', ['\CRM_Utils_System', 'migrateExternUrl'], 1000);
+    // Not a BAO class so it can't implement hookInterface
+    $dispatcher->addListener('hook_civicrm_post', ['CRM_Utils_Recent', 'on_hook_civicrm_post']);
     $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findConstPermissions'], 975);
     $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findCiviPermissions'], 950);
     $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findCmsPermissions'], 925);