CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • ACL Hooks and the ACL Cache
Pages: [1]

Author Topic: ACL Hooks and the ACL Cache  (Read 927 times)

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
ACL Hooks and the ACL Cache
June 07, 2010, 08:19:06 pm
I'm working on some code to simplify the "where" clause in a system with many, many groups, enough that MySQL's limit on the number of LEFT JOINs is causing real pain.

Part of the problem is that I'm not getting the way these tables are glued together.  In particular, I don't understand what the links from civicrm_saved_search are all about.

What's the logic here?  Is it written down anywhere?

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Re: ACL Hooks and the ACL Cache
June 07, 2010, 09:46:56 pm
After going a couple of rounds with Lobo on IRC, I've gotten at least definitions of some of this stuff.  The basic structure appears to be more or less unchanged between 1.9 and 3.1 at least.

I used the civicrm_og_sync module to create a new organic group; here's what gets generated in CiviCRM 1.9.  3.1 is likely very similar, since the tables are almost unchanged:
Code: [Select]
mysql> select * from civicrm_acl_entity_role order by id desc limit 1 \G
*************************** 1. row ***************************
          id: 3028
   domain_id: 1
 acl_role_id: 3013
entity_table: civicrm_group
   entity_id: 1219
   is_active: 1
1 row in set (0.00 sec)

mysql> select * from  civicrm_group where name like 'califor%' \G
*************************** 1. row ***************************
             id: 1218
      domain_id: 1
           name: California
          title: California
    description: Because US group needs a CA affiliate
         source: OG Sync Group :11322:
saved_search_id: NULL
      is_active: 1
     visibility: User and User Admin Only
   where_clause:  ( `civicrm_group_contact-1218`.group_id = (1218) AND `civicrm_group_contact-1218`.status IN ("Added") )
  select_tables: a:11:{s:15:"civicrm_contact";i:1;s:18:"civicrm_individual";i:1;s:16:"civicrm_location";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:28:"`civicrm_group_contact-1218`";s:170:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1218` ON contact_a.id = `civicrm_group_contact-1218`.contact_id  AND `civicrm_group_contact-1218`.group_id = 1218 ";s:6:"gender";i:1;}
   where_tables: a:2:{s:15:"civicrm_contact";i:1;s:28:"`civicrm_group_contact-1218`";s:170:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1218` ON contact_a.id = `civicrm_group_contact-1218`.contact_id  AND `civicrm_group_contact-1218`.group_id = 1218 ";}
     group_type: 2
*************************** 2. row ***************************
             id: 1219
      domain_id: 1
           name: California: Administrator
          title: California: Administrator
    description: Because US group needs a CA affiliate
         source: OG Sync Group ACL :11322:
saved_search_id: NULL
      is_active: 1
     visibility: User and User Admin Only
   where_clause:  ( `civicrm_group_contact-1219`.group_id = (1219) AND `civicrm_group_contact-1219`.status IN ("Added") )
  select_tables: a:11:{s:15:"civicrm_contact";i:1;s:18:"civicrm_individual";i:1;s:16:"civicrm_location";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:28:"`civicrm_group_contact-1219`";s:170:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1219` ON contact_a.id = `civicrm_group_contact-1219`.contact_id  AND `civicrm_group_contact-1219`.group_id = 1219 ";s:6:"gender";i:1;}
   where_tables: a:2:{s:15:"civicrm_contact";i:1;s:28:"`civicrm_group_contact-1219`";s:170:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1219` ON contact_a.id = `civicrm_group_contact-1219`.contact_id  AND `civicrm_group_contact-1219`.group_id = 1219 ";}
     group_type: 1
2 rows in set (0.00 sec)

mysql> select * from civicrm_acl order by id desc limit 1 \G
*************************** 1. row ***************************
          id: 485
   domain_id: 1
        name: NULL
        deny: 0
entity_table: civicrm_acl_role
   entity_id: 3013
   operation: Edit
object_table: civicrm_saved_search
   object_id: 1218
   acl_table: NULL
      acl_id: NULL
   is_active: 1
1 row in set (0.00 sec)


mysql> select * from civicrm_option_value order by id desc limit 1 \G
*************************** 1. row ***************************
             id: 585
option_group_id: 8
          label: California: Administrator
          value: 3013
           name: NULL
       grouping: NULL
         filter: NULL
     is_default: 0
         weight: 3013
    description: OG Sync Group ACL :11322:
    is_optgroup: 0
    is_reserved: 0
      is_active: 1
1 row in set (0.00 sec)

mysql> select * from civicrm_option_group where id = 8 \G
*************************** 1. row ***************************
         id: 8
  domain_id: 1
       name: acl_role
      label: NULL
description: ACL Role
is_reserved: 0
  is_active: 1
1 row in set (0.00 sec)

Note that the link to Organic Groups is through the source field,  that civicrm_acl_role actually refers to strings in an option group, and that  object_table: civicrm_saved_search refers the civicrm_group object that the ACL governs.

Lobo isn't sure how all this ended up that way, but apparently, these records are correctly configured.

Alas, many of my 1.9 records are trashed, and I'll probably have to reconstruct this stuff manually.  But at least it's possible to see what the fields should be.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • ACL Hooks and the ACL Cache

This forum was archived on 2017-11-26.