aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/access.php48
1 files changed, 29 insertions, 19 deletions
diff --git a/engine/lib/access.php b/engine/lib/access.php
index 68a01dfad..30febb799 100644
--- a/engine/lib/access.php
+++ b/engine/lib/access.php
@@ -592,31 +592,41 @@ function add_user_to_access_collection($user_guid, $collection_id) {
return false;
}
- if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0)
- && $user = get_user($user_guid)) {
- global $CONFIG;
+ $user = get_user($user_guid);
+ if (!$user) {
+ return false;
+ }
- $params = array(
- 'collection_id' => $collection_id,
- 'user_guid' => $user_guid
- );
+ // to add someone to a collection, the user must be a member of the collection or
+ // no one must own it
+ if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0)) {
+ $result = true;
+ } else {
+ $result = false;
+ }
+
+ $params = array(
+ 'collection_id' => $collection_id,
+ 'collection' => $collection,
+ 'user_guid' => $user_guid
+ );
- if (!elgg_trigger_plugin_hook('access:collections:add_user', 'collection', $params, true)) {
- return false;
- }
+ $result = elgg_trigger_plugin_hook('access:collections:add_user', 'collection', $params, $result);
+ if ($result == false) {
+ return false;
+ }
- try {
- $query = "insert into {$CONFIG->dbprefix}access_collection_membership"
+ try {
+ global $CONFIG;
+ $query = "insert into {$CONFIG->dbprefix}access_collection_membership"
. " set access_collection_id = {$collection_id}, user_guid = {$user_guid}";
- insert_data($query);
- } catch (DatabaseException $e) {
- // nothing.
- }
- return true;
-
+ insert_data($query);
+ } catch (DatabaseException $e) {
+ // nothing.
+ return false;
}
- return false;
+ return true;
}
/**