fixed bug in the original function
authorsystopia <endres@systopia.de>
Wed, 12 Oct 2016 20:19:50 +0000 (21:19 +0100)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 24 Oct 2016 02:17:29 +0000 (15:17 +1300)
CRM/Contact/BAO/Contact/Permission.php

index e4ffc92d37ac9d76914e4f3b1e32653de2e5a828..44ba8e7d37eb128c47416e955ec8e2a0a5646967 100644 (file)
@@ -188,9 +188,10 @@ WHERE contact_a.id = %1 AND $permission";
    *   Should we force a recompute.
    */
   public static function cache($userID, $type = CRM_Core_Permission::VIEW, $force = FALSE) {
-    static $_processed = array();
+    static $_processed = array( CRM_Core_Permission::VIEW => array(),
+                                CRM_Core_Permission::EDIT => array());
 
-    if ($type = CRM_Core_Permission::VIEW) {
+    if ($type == CRM_Core_Permission::VIEW) {
       $operationClause = " operation IN ( 'Edit', 'View' ) ";
       $operation = 'View';
     }
@@ -200,7 +201,8 @@ WHERE contact_a.id = %1 AND $permission";
     }
 
     if (!$force) {
-      if (!empty($_processed[$userID])) {
+      // skip if already calculated
+      if (!empty($_processed[$type][$userID])) {
         return;
       }
 
@@ -214,7 +216,7 @@ AND    $operationClause
       $params = array(1 => array($userID, 'Integer'));
       $count = CRM_Core_DAO::singleValueQuery($sql, $params);
       if ($count > 0) {
-        $_processed[$userID] = 1;
+        $_processed[$type][$userID] = 1;
         return;
       }
     }
@@ -238,8 +240,7 @@ ON DUPLICATE KEY UPDATE
          contact_id=VALUES(contact_id),
          operation=VALUES(operation)"
     );
-
-    $_processed[$userID] = 1;
+    $_processed[$type][$userID] = 1;
   }
 
   /**