From 42f0bf162b77ef27b0e93a6b2e882491cdfd8752 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 20 Aug 2021 15:54:06 -0400 Subject: [PATCH] Move acl delete logic to an event listener --- CRM/ACL/BAO/ACL.php | 21 +++++++++++++-------- Civi/Core/Event/EventScanner.php | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index e105339192..82aaf8dabc 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -18,7 +18,7 @@ /** * Access Control List */ -class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL { +class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL implements \Civi\Test\HookInterface { /** * Available operations for pseudoconstant. @@ -433,16 +433,21 @@ SELECT g.* * Delete ACL records. * * @param int $aclId - * ID of the ACL record to be deleted. - * + * @deprecated */ public static function del($aclId) { - // delete all entries from the acl cache - CRM_ACL_BAO_Cache::resetCache(); + self::deleteRecord(['id' => $aclId]); + } - $acl = new CRM_ACL_DAO_ACL(); - $acl->id = $aclId; - $acl->delete(); + /** + * Event fired before an action is taken on an ACL record. + * @param \Civi\Core\Event\PreEvent $event + */ + public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) { + // Reset cache when deleting an ACL record + if ($event->action === 'delete') { + CRM_ACL_BAO_Cache::resetCache(); + } } /** diff --git a/Civi/Core/Event/EventScanner.php b/Civi/Core/Event/EventScanner.php index 912e313168..9b6c93daa5 100644 --- a/Civi/Core/Event/EventScanner.php +++ b/Civi/Core/Event/EventScanner.php @@ -53,7 +53,7 @@ class EventScanner { * @param string|null $self * If the target $class is focused on a specific entity/form/etc, use the `$self` parameter to specify it. * This will activate support for `self_{$event}` methods. - * Ex: if '$self' is 'Contact', then 'function self_hook_civicrm_pre()' maps to 'hook_civicrm_pre::Contact'. + * Ex: if '$self' is 'Contact', then 'function self_hook_civicrm_pre()' maps to 'on_hook_civicrm_pre::Contact'. * @return array * List of events/listeners. Format is compatible with 'getSubscribedEvents()'. * Ex: ['some.event' => [['firstFunc'], ['secondFunc']] -- 2.25.1