Notice: Undefined property: stdClass::$status in user_save() (line 547 of /usr/local/apache2/htdocs/drupal7/modules/user/user.module).

Steps to reproduce:

$account = new stdClass;
$account->uid = $uid;
$fields['mail'] = $newemailaddress;
$account = user_save($account, $fields);

If this line is added the warning is not generated.
$account->status = 1;

user_save documentation states that only the uid property is required.

CommentFileSizeAuthor
#2 user-save-status-change-1049090.patch664 byteslyricnz

Comments

Chris Gillis’s picture

I am also having this issue.
It seems this would only be a matter of changing line 547 from
if (isset($edit['status']) && $edit['status'] != $account->status) {
to
if (isset($edit['status']) && isset($account->status) && $edit['status'] != $account->status) {

lyricnz’s picture

Status: Active » Needs review
StatusFileSize
new664 bytes

The sample code above doesn't cause this error because you're not attempting to set status (which is where the notice comes from). Here's real sample code

$account = new stdClass;
$account->uid = 3;
$fields['status'] = 0;
$account = user_save($account, $fields);

In this case, I think the correct fix is to check the status being saved (in $edit) against the $user that was just loaded, not the one passed in $account.


      // Refresh user object.   
      $user = user_load($account->uid, TRUE);
      // Make the original, unchanged user account available to update hooks.
      if (isset($account->original)) {
        $user->original = $account->original;
      }

      // Send emails after we have the new user object.
      if (isset($edit['status']) && $edit['status'] != $user->status) { // <============ changed from $account->status
        // The user's status is changing; conditionally send notification email.
        $op = $edit['status'] == 1 ? 'status_activated' : 'status_blocked';
        _user_mail_notify($op, $user);
      }

Status: Needs review » Needs work

The last submitted patch, user-save-status-change-1049090.patch, failed testing.

lyricnz’s picture

Status: Needs work » Needs review
lyricnz’s picture

Status: Needs review » Closed (duplicate)

There are other problems in the same area - this is probably covered by #999004: user_save() relies on $edit instead of $account.