The Documentation specifies the following:
$account: (optional) The user object to modify or add. If you want to modify an existing user account, you will need to ensure that (a) $account is an object, and (b) you have set $account->uid to the numeric user ID of the user account you wish to modify. If you want to create a new user account, you can set $account->is_new to TRUE or omit the $account->uid field.
What it fails to say here is that you must add also $account->pass, $account->status, and $account->roles for this to function properly, and they must be the same as what is already in the current user object.
According to this documentation I should be able to build a standard object with just a uid property and have no issues saving a user.
The bit about roles is here:
// Reload user roles if provided.
if ($account->roles != $account->original->roles) {
db_delete('users_roles')->condition('uid', $account->uid)->execute();
$query = db_insert('users_roles')->fields(array('uid', 'rid'));
foreach (array_keys($account->roles) as $rid) {
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
$query->values(array(
'uid' => $account->uid,
'rid' => $rid,
));
}
}
$query->execute();
}
The bit about passwords is here:
// If the password changed, delete all open sessions and recreate
// the current one.
if ($account->pass != $account->original->pass) {
drupal_session_destroy_uid($account->uid);
if ($account->uid == $GLOBALS['user']->uid) {
drupal_session_regenerate();
}
}
The bit about status is here:
// Delete a blocked user's sessions to kick them if they are online.
if ($account->original->status != $account->status && $account->status == 0) {
drupal_session_destroy_uid($account->uid);
}
And Here:
// Send emails after we have the new user object.
if ($account->status != $account->original->status) {
// The user's status is changing; conditionally send notification email.
$op = $account->status == 1 ? 'status_activated' : 'status_blocked';
_user_mail_notify($op, $account);
}
Comment | File | Size | Author |
---|---|---|---|
#1 | drupal-make_user_save_not_need_pass_status_and_roles-2130385-1.patch | 3.4 KB | generalredneck |
Comments
Comment #1
generalredneckThis patch will remove a load of notices that would be caused by not providing pass, status, picture and roles. Also it behaves as a switch to keep that particular property unchanged. Please review and let me know if you see any holes.