From: Coleman Watts Date: Sat, 21 Aug 2021 19:11:37 +0000 (-0400) Subject: CRM_Utils_Recent - Use hook listener to delete items X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=54043949b9c6b7fea1ac73f0967c4a2bdcfb5aab;p=civicrm-core.git CRM_Utils_Recent - Use hook listener to delete items dev/core#2757 --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 922abde289..d60d201b0c 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -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 diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 65846ce83a..5014e4a0cd 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -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; } diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 48e5802ab2..b9c6be59ea 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -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); } /** diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index cacd788ac9..c4aa4de85e 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -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; } diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 10d7689d48..840878bc6c 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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; } diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 90b9a2f6aa..4d73cf2566 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -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; } diff --git a/CRM/Grant/BAO/Grant.php b/CRM/Grant/BAO/Grant.php index bc33e04c80..c2e4dad3c0 100644 --- a/CRM/Grant/BAO/Grant.php +++ b/CRM/Grant/BAO/Grant.php @@ -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); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index edc63eda52..8e95311d44 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -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; } diff --git a/CRM/Pledge/BAO/Pledge.php b/CRM/Pledge/BAO/Pledge.php index 63078610fd..61f95340bc 100644 --- a/CRM/Pledge/BAO/Pledge.php +++ b/CRM/Pledge/BAO/Pledge.php @@ -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; } diff --git a/CRM/Utils/Recent.php b/CRM/Utils/Recent.php index 59818c0b01..231f4af395 100644 --- a/CRM/Utils/Recent.php +++ b/CRM/Utils/Recent.php @@ -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. * diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 72e69c4762..c680216844 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -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);