Closed (fixed)
Project:
Auto Assign Role
Version:
5.x-1.1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
23 Feb 2008 at 19:13 UTC
Updated:
7 Sep 2008 at 07:23 UTC
Jump to comment: Most recent file
I am using Drpal 5.7. The role is assigned and inserted, but during the user_save it deletes them. I am using autoassign, one role. In the user.module:user_save I found.
// Save user roles (delete just to be safe).
if (is_array($array['roles'])) {
db_query('DELETE FROM {users_roles} WHERE uid = %d', $array['uid']);
foreach (array_keys($array['roles']) as $rid) {
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $array['uid'], $rid);
}
}
}
Well array['roles'] is an empty array. So I added
!empty($array['roles']) &&
It happens in two locations.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | autoassignrole.module.patch | 1.21 KB | sarvab |
Comments
Comment #1
sarvab commentedI'm experiencing the same problem. In pearcec's case above, the $array['roles'] object is empty which is causing his troubles, however I believe that that is the correct way of doing it inside user_save so that you can remove all of a user's roles and also to make role insertion/deletion all happen in one place.
In my case, the array is not empty because login togoboggan is setting the pre-authenticated role in the $array['roles'] array and user_save is creating the users roles based on that and thus erasing the autoassignrole role.
I'm attaching a patch that works fine with me and integrates with login_togobban (and pre-auth roles) by taking advantage of user_save's own mechanism to manage roles.
Comment #2
cyberswat commentedComment #3
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.