/** * update a security set * @param int $setId * @param int $onlyForUserId * @return void */ public static function updateSecuritySet($setId, $onlyForUserId = false) { /* get set */ $set = ''; $res = DB\dbQuery('SELECT `set` FROM tree_acl_security_sets WHERE id = $1', $setId); if ($r = $res->fetch_assoc()) { $set = $r['set']; } $res->close(); /* end of get set*/ $objIds = explode(',', $set); $everyoneGroupId = static::getSystemGroupId('everyone'); $users = array(); $updatingUser = false; /* iterate the full set of access credentials(users and/or groups) and estimate access for every user including everyone group */ if (!empty($set)) { $objectId = $objIds[sizeof($objIds) - 1]; $groupUsers = array(); if (!empty($onlyForUserId)) { $groupUsers = static::getGroupUserIds($onlyForUserId); if (empty($groupUsers)) { $updatingUser = true; $users[$onlyForUserId] = static::getEstimatedUserAccessForObject($objectId, $onlyForUserId); } } if (!$updatingUser) { $res = DB\dbQuery('SELECT DISTINCT u.id ,u.`type` FROM tree_acl a JOIN users_groups u on a.user_group_id = u.id WHERE a.node_id in(0' . implode(',', $objIds) . ') ORDER BY u.`type`'); while ($r = $res->fetch_assoc()) { $groupUsers = array(); if ($r['id'] == $everyoneGroupId || $r['type'] == 2) { $groupUsers[] = $r['id']; } else { $groupUsers = Security::getGroupUserIds($r['id']); } foreach ($groupUsers as $userId) { if (empty($users[$userId])) { $users[$userId] = static::getEstimatedUserAccessForObject($objectId, $userId); } } } $res->close(); } } /* end of iterate the full set of access credentials(users and/or groups) and estimate access for every user including everyone group */ /* update set in database */ $res = DB\dbQuery('DELETE FROM tree_acl_security_sets_result WHERE security_set_id = $1 and (ISNULL($2) OR ($2 = user_id))', array($setId, $updatingUser ? $onlyForUserId : null)); $sql = 'INSERT INTO tree_acl_security_sets_result (security_set_id ,user_id ,bit0 ,bit1 ,bit2 ,bit3 ,bit4 ,bit5 ,bit6 ,bit7 ,bit8 ,bit9 ,bit10 ,bit11) VALUES ($1 ,$2 ,$3 ,$4 ,$5 ,$6 ,$7 ,$8 ,$9 ,$10 ,$11 ,$12 ,$13 ,$14)'; foreach ($users as $userId => $access) { $params = array($setId, $userId); for ($i = 0; $i < sizeof($access[0]); $i++) { $params[] = empty($access[1][$i]) && $access[0][$i] > 0 ? 1 : 0; } $res = DB\dbQuery($sql, $params); } $res = DB\dbQuery('UPDATE tree_acl_security_sets SET updated = 0 WHERE id = $1', $setId); /* end of update set in database */ }