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
Comment #1
christefano commentedHere's a patch. Let's get this in.
Comment #2
mlncn commentedThis 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
Comment #3
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.