So user_save() claims to return a fully-loaded user object but in some cases it doesn't seem to. I'm filing this as a bug report, but if my example is flawed it might just be a support request.
Suppose, for example, we are creating a new user. Mimicking user_external_login_register(), we call something like
$edit = array(
'name' => user_password(),
'pass' => user_password(),
'init' => user_password(),
'status' => 1,
);
$account = user_save(drupal_anonymous_user(), $edit);
print_r($account);
Running this with drush scr
returns something like:
stdClass Object
(
[name] => ew6A4Jy2jR
[pass] => $S$C54k3AiWEzHzrCe8XrfIhKd0MaI6baCNtFH5LknMHjSC66so1AO9
[init] => hELVnoibpg
[status] => 1
[uid] => 188
[created] => 1307060932
[mail] =>
[theme] =>
[signature] =>
[access] => 0
[login] => 0
[language] =>
[picture] => 0
[roles] => Array
(
[2] => authenticated user
)
)
This is not a fully-loaded $user object. For example, it's missing the timezone
field (as reported in #1176904: Initial login generates a timezone warning). Am I doing something wrong here? Is user_save flawed? Or is the documentation wrong?
Comments
Comment #1
justintime CreditAttribution: justintime commentedSubscribe. Having the same problem as indicated in #1176904: Initial login generates a timezone warning.
Comment #2
geerlingguy CreditAttribution: geerlingguy commentedThis same problem causes things like #935592: User picture is deleted after calls to user_save(), since sometimes a $user object contains just the picture file ID (an integer), and other times, the $user object contains the full picture file object (an object).
It would be nice if we could depend on the user object being consistent :)
And I'm guessing this would still be a problem in 8.x... and should be solved there first.
Comment #3
longwaveuser_save() no longer exists in D8, instead you must call ->save() on a User entity, so I am not sure this is an issue there.
Comment #4
geerlingguy CreditAttribution: geerlingguy commentedIt would be good to confirm before moving back to 7.x, though—I haven't had time to look through all the changes to user-related functionality in D8, and a lot has changed... but a lot has remained the same :)
Comment #5
lokapujyaJust verified that in D8, after calling save() on the user entity, that the timezone field gets set. We have UserSaveTest; It only checks to see if the user can be loaded by name. Do we need to expand the test to prove that it's "fully loaded"? The webTestBase drupalCreateUser() function claims to return a fully loaded user object and it's just doing save() on the entity.
Comment #6
ws.agency CreditAttribution: ws.agency at Websolutions Agency commenteduser_save is removed from D8, therefore closing this ticket.
Comment #7
lokapujyaBut we can still save() the user object. I think we still need to answer #5.
Comment #10
dpiuser_save()
no longer exists. everything goes through the same entity storage controller.Closing as outdated.
Comment #11
dpi