From: eileen Date: Mon, 22 Mar 2021 21:10:11 +0000 (+1300) Subject: [REF] Simplify BAO_ACL table references X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=51f5878d50af23001747af1ce8020daa8e5675ba;p=civicrm-core.git [REF] Simplify BAO_ACL table references It does not appear to me, from my testing that the value in entity_table could be something other than the actual table name (in fact I suspect it would only ever be civicrm_acl_role - I'm working to confirm that). This simplifies and switches to executeQuery which is multilingual aware --- diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index f1f8cb0df8..64e5bc6e71 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -88,17 +88,12 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL { */ protected static function getACLs(int $contact_id) { $results = []; - - $rule = new CRM_ACL_BAO_ACL(); - - $contact = CRM_Contact_BAO_Contact::getTableName(); - $query = " SELECT acl.* FROM civicrm_acl acl - WHERE acl.entity_table = '$contact' + WHERE acl.entity_table = 'civicrm_contact' AND acl.entity_id = $contact_id"; - $rule->query($query); + $rule = CRM_Core_DAO::executeQuery($query); while ($rule->fetch()) { $results[$rule->id] = $rule->toArray(); @@ -123,20 +118,16 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL { protected static function getACLRoles($contact_id = NULL) { $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer'); - $rule = new CRM_ACL_BAO_ACL(); - - $contact = CRM_Contact_BAO_Contact::getTableName(); - $query = 'SELECT acl.* FROM civicrm_acl acl'; $where = ['acl.entity_table = "civicrm_acl_role" AND acl.entity_id IN (' . implode(',', array_keys(CRM_Core_OptionGroup::values('acl_role'))) . ')']; if (!empty($contact_id)) { - $where[] = " acl.entity_table = '$contact' AND acl.is_active = 1 AND acl.entity_id = $contact_id"; + $where[] = " acl.entity_table = 'civicrm_contact' AND acl.is_active = 1 AND acl.entity_id = $contact_id"; } $results = []; - $rule->query($query . ' WHERE ' . implode(' AND ', $where)); + $rule = CRM_Core_DAO::executeQuery($query . ' WHERE ' . implode(' AND ', $where)); while ($rule->fetch()) { $results[$rule->id] = $rule->toArray(); @@ -160,23 +151,19 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL { protected static function getGroupACLs($contact_id, $aclRoles = FALSE) { $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer'); - $rule = new CRM_ACL_BAO_ACL(); - - $c2g = CRM_Contact_BAO_GroupContact::getTableName(); - $group = CRM_Contact_BAO_Group::getTableName(); $results = []; if ($contact_id) { $query = " SELECT acl.* FROM civicrm_acl acl - INNER JOIN $c2g group_contact + INNER JOIN civicrm_group_contact group_contact ON acl.entity_id = group_contact.group_id - WHERE acl.entity_table = '$group' + WHERE acl.entity_table = 'civicrm_group' AND group_contact.contact_id = $contact_id AND group_contact.status = 'Added'"; - $rule->query($query); + $rule = CRM_Core_DAO::executeQuery($query); while ($rule->fetch()) { $results[$rule->id] = $rule->toArray();