From ed2f375721d90a9466e68a7b0abaa2e1d6f36b0c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 23 Aug 2021 11:30:11 +1200 Subject: [PATCH] Extract ACL contact cache clearing part out This allows us to be nuanced in the acl delete part & still clear the contact cache part --- CRM/ACL/BAO/Cache.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/CRM/ACL/BAO/Cache.php b/CRM/ACL/BAO/Cache.php index 138ee803f2..eac03d8b10 100644 --- a/CRM/ACL/BAO/Cache.php +++ b/CRM/ACL/BAO/Cache.php @@ -153,12 +153,28 @@ WHERE modified_date IS NULL ], ]; CRM_Core_DAO::singleValueQuery($query, $params); + self::flushACLContactCache(); + } + + /** + * Remove Entries from `civicrm_acl_contact_cache` for a specific ACLed user + * @param int $userID - contact_id of the ACLed user + * + */ + public static function deleteContactCacheEntry($userID) { + CRM_Core_DAO::executeQuery("DELETE FROM civicrm_acl_contact_cache WHERE user_id = %1", [1 => [$userID, 'Positive']]); + } + + /** + * Flush the contents of the acl contact cache. + */ + protected static function flushACLContactCache(): void { unset(Civi::$statics['CRM_ACL_API']); // CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); // No, force-commits transaction // CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_acl_contact_cache"); // Transaction-safe if (CRM_Core_Transaction::isActive()) { CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, function () { - CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); + CRM_Core_DAO::singleValueQuery('TRUNCATE TABLE civicrm_acl_contact_cache'); }); } else { @@ -166,13 +182,4 @@ WHERE modified_date IS NULL } } - /** - * Remove Entries from `civicrm_acl_contact_cache` for a specific ACLed user - * @param int $userID - contact_id of the ACLed user - * - */ - public static function deleteContactCacheEntry($userID) { - CRM_Core_DAO::executeQuery("DELETE FROM civicrm_acl_contact_cache WHERE user_id = %1", [1 => [$userID, 'Positive']]); - } - } -- 2.25.1