Posted by spficklin on February 11, 2011 at 3:55pm
1 follower
| Project: | Organic Groups Registration Keys |
| Version: | 6.x-1.4 |
| Component: | Code |
| Category: | bug report |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
The following code currently exists in the og_reg_keys_join_submit function:
// Use og_save_subscription() to get around og_subscribe_user()'s
// selectivity checks.
og_save_subscription($gid, $user->uid, array('is_active' => 1));
// Existing user so preserve roles as user_save is destructive
$roles = $user->roles + array(variable_get('og_reg_keys_role', DRUPAL_AUTHENTICATED_RID) => 1);
user_save($user, array('roles' => $roles));This code causes a problem with Rules and Rule Triggers. If I create a rule to add a role to a user when he/she subscribes to the organic group then the trigger executes correctly and adds the permission. However, the user_save function above uses the global $user variable which does not reflect the update made by the trigger. So, when the user_save function call is made in the code above it overwrites the change made by the trigger and sets the users' roles back to the way they were before the trigger was executed. If the code is reordered in this way the problem is corrected:
// Existing user so preserve roles as user_save is destructive
$roles = $user->roles + array(variable_get('og_reg_keys_role', DRUPAL_AUTHENTICATED_RID) => 1);
user_save($user, array('roles' => $roles));
// Use og_save_subscription() to get around og_subscribe_user()'s
// selectivity checks.
og_save_subscription($gid, $user->uid, array('is_active' => 1));