RT#765026, patch for null values in civicrm_acl_cache
[civicrm-core.git] / CRM / ACL / BAO / Cache.php
index 138ee803f2cac21c297166c6dbea9157fd7fb685..97a92f5318bd3193ce6cde8f4255ce83e45e5eec 100644 (file)
@@ -64,9 +64,15 @@ SELECT acl_id
 ";
     $params = [1 => [$id, 'Integer']];
 
+    /* this is related to RT#765026
+       Something is occasionally inserting records in civicrm_acl_cache with id null.
+       That causes i for our anonymous visitors who want to sign petitions.
+       Removed. Ward, 2012-07-20 */
+    /*
     if ($id == 0) {
-      $query .= " OR contact_id IS NULL";
+       query .= " OR contact_id IS NULL";
     }
+    t*/
 
     $dao = CRM_Core_DAO::executeQuery($query, $params);
 
@@ -153,12 +159,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 +188,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']]);
-  }
-
 }