Fix some missing places where prioritisation is not incorporated
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 22 Jun 2023 21:34:56 +0000 (07:34 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 23 Jun 2023 18:04:25 +0000 (04:04 +1000)
CRM/ACL/BAO/ACL.php

index 77311c8cf741dd1d74e7a5b8e2341a7618f4f2e9..9a7e65e9fe13569762210cfd079a54300640afcd 100644 (file)
@@ -228,16 +228,18 @@ SELECT count( a.id )
     if (!empty($acls)) {
       $aclKeys = array_keys($acls);
       $aclKeys = implode(',', $aclKeys);
-
+      $orderBy = 'a.object_id';
+      if (array_key_exists('priority', CRM_ACL_BAO_ACL::getSupportedFields())) {
+        $orderBy .= ',a.priority';
+      }
       $query = "
-SELECT   a.operation, a.object_id
+SELECT   a.operation, a.object_id,a.deny
   FROM   civicrm_acl_cache c, civicrm_acl a
  WHERE   c.acl_id       =  a.id
    AND   a.is_active    =  1
    AND   a.object_table = 'civicrm_group'
    AND   a.id        IN ( $aclKeys )
-   AND   a.deny         = 0
-ORDER BY a.object_id
+ORDER BY {$orderBy}
 ";
 
       $dao = CRM_Core_DAO::executeQuery($query);
@@ -252,24 +254,12 @@ ORDER BY a.object_id
             $whereClause = ' ( 1 ) ';
             break;
           }
-          $ids[] = $dao->object_id;
-        }
-      }
-      $denyQuery = "SELECT   a.operation, a.object_id
-  FROM   civicrm_acl_cache c, civicrm_acl a
- WHERE   c.acl_id       =  a.id
-   AND   a.is_active    =  1
-   AND   a.object_table = 'civicrm_group'
-   AND   a.id        IN ( $aclKeys )
-   AND   a.deny         = 1
-   AND   a.object_id IN (%1)
-ORDER BY a.object_id
-";
-      if (!empty($ids)) {
-        $denyDao = CRM_Core_DAO::executeQuery($denyQuery, [1 => [implode(',', $ids), 'CommaSeparatedIntegers']]);
-        while ($denyDao->fetch()) {
-          $key = array_search($denyDao->object_id, $ids);
-          unset($ids[$key]);
+          if (!$dao->deny) {
+            $ids[] = $dao->object_id;
+          }
+          else {
+            $ids = array_diff($ids, [$dao->object_id]);
+          }
         }
       }
 
@@ -490,7 +480,7 @@ SELECT   a.operation,a.object_id,a.deny
    AND   a.is_active    =  1
    AND   a.object_table = %1
    AND   a.id        IN ( $aclKeys )
-ORDER BY a.object_id
+ORDER BY {$orderBy}
 ";
     $params = [1 => [$tableName, 'String']];
     $dao = CRM_Core_DAO::executeQuery($query, $params);