Posted by abhaga on October 11, 2008 at 11:25pm
| Project: | Registration role |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Hi,
The current approach of directly making an entry in the users_roles table does not work since the user_save function deletes the users_roles table entry before restoring it from the original user options array.
The correct thing to do would be to add the required role to that array (it is passed in the hook) and let user_save do the database entry.
So the current code
function registration_role_user ($op, &$edit, &$user, $category=null)
{
if ($op == "insert" && $rid = variable_get('registration_role_roles', ''))
{
// below does not seem safe! or necessary for insert. Commented out
// clear first
// db_query( 'DELETE FROM {users_roles} WHERE uid = %d', $user->uid );
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
}
}should change to
function registration_role_user ($op, &$edit, &$user, $category=null)
{
if ($op == "insert" && $rid = variable_get('registration_role_roles', ''))
{
// below does not seem safe! or necessary for insert. Commented out
// clear first
// db_query( 'DELETE FROM {users_roles} WHERE uid = %d', $user->uid );
$edit['roles'][$rid] = array();
}
} regards,
Abhaya
Comments
#1
Here's a patch. Let's get this in.
#2
This has been committed to the Drupal 5 dev branch. I haven't tested it myself, if someone has tested this patch or can test the D5 dev from CVS, I'll make a new release.
Sorry for the slow response here.
benjamin, Agaric Design Collective
#3
Automatically closed -- issue fixed for two weeks with no activity.