2010062302.php 973 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Make sure that everyone who belongs to a group is a member of the group's access collection
  4. */
  5. elgg_set_ignore_access(TRUE);
  6. $params = array('type' => 'group', 'limit' => 0);
  7. $groups = elgg_get_entities($params);
  8. if ($groups) {
  9. foreach ($groups as $group) {
  10. $acl = $group->group_acl;
  11. $query = "SELECT u.guid FROM {$CONFIG->dbprefix}users_entity u
  12. JOIN {$CONFIG->dbprefix}entity_relationships r
  13. ON u.guid = r.guid_one AND r.relationship = 'member' AND r.guid_two = $group->guid
  14. LEFT JOIN {$CONFIG->dbprefix}access_collection_membership a
  15. ON u.guid = a.user_guid AND a.access_collection_id = $acl
  16. WHERE a.user_guid IS NULL";
  17. $results = get_data($query);
  18. if ($results != FALSE) {
  19. foreach ($results as $user) {
  20. $insert = "INSERT INTO {$CONFIG->dbprefix}access_collection_membership
  21. (user_guid, access_collection_id) VALUES ($user->guid, $acl)";
  22. insert_data($insert);
  23. }
  24. }
  25. }
  26. }
  27. elgg_set_ignore_access(FALSE);