aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/upgrades/2010062302.php
blob: fe33e12eac98d88b1d186b305e93715c6968716b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

/**
 * Make sure that everyone who belongs to a group is a member of the group's access collection
 */


elgg_set_ignore_access(TRUE);

$params = array('type' => 'group', 'limit' => 0);
$groups = elgg_get_entities($params);
if ($groups) {
	foreach ($groups as $group) {
		$acl = $group->group_acl;

		$query = "SELECT u.guid FROM {$CONFIG->dbprefix}users_entity u
			JOIN {$CONFIG->dbprefix}entity_relationships r
				ON u.guid = r.guid_one AND r.relationship = 'member' AND r.guid_two = $group->guid
			LEFT JOIN {$CONFIG->dbprefix}access_collection_membership a
				ON u.guid = a.user_guid AND a.access_collection_id = $acl
				WHERE a.user_guid IS NULL";

		$results = get_data($query);
		if ($results != FALSE) {
			foreach ($results as $user) {
				$insert = "INSERT INTO {$CONFIG->dbprefix}access_collection_membership
							(user_guid, access_collection_id) VALUES ($user->guid, $acl)";
				insert_data($insert);
			}
		}
	}
}
elgg_set_ignore_access(FALSE);