Commit 037848ad authored by David_Rothstein's avatar David_Rothstein

Issue #935592 by pillarsdotnet, lokapujya, David_Rothstein, John Franklin,...

Issue #935592 by pillarsdotnet, lokapujya, David_Rothstein, John Franklin, amitgoyal, joshi.rohit100, sivaji, mgifford, peximo, wodenx, Romlam, Owen Barton, alpritt, beejeebus | macgirvin: Fixed User picture is deleted after calls to user_save().
parent d7ea3ba5
Drupal 7.33, xxxx-xx-xx (development version)
-----------------------
- Fixed a bug which caused user pictures to be removed from the user object
after saving, and resulted in data loss if the user account was subsequently
re-saved.
- Fixed a bug in which field_has_data() did not return TRUE for fields that
only had data in older entity revisions, leading to loss of the field's data
when the field configuration was edited.
......
......@@ -501,12 +501,17 @@ function user_save($account, $edit = array(), $category = 'account') {
file_usage_delete($account->original->picture, 'user', 'user', $account->uid);
file_delete($account->original->picture);
}
// Save the picture object, if it is set. drupal_write_record() expects
// $account->picture to be a FID.
$picture = empty($account->picture) ? NULL : $account->picture;
$account->picture = empty($account->picture->fid) ? 0 : $account->picture->fid;
// Do not allow 'uid' to be changed.
$account->uid = $account->original->uid;
// Save changes to the user table.
$success = drupal_write_record('users', $account, 'uid');
// Restore the picture object.
$account->picture = $picture;
if ($success === FALSE) {
// The query failed - better to abort the save than risk further
// data loss.
......
......@@ -1127,6 +1127,17 @@ class UserPictureTestCase extends DrupalWebTestCase {
$pic_path2 = $this->saveUserPicture($image);
$this->assertNotEqual($pic_path, $pic_path2, 'Filename of second picture is different.');
// Check if user picture has a valid file ID after saving the user.
$account = user_load($this->user->uid, TRUE);
$this->assertTrue(is_object($account->picture), 'User picture object is valid after user load.');
$this->assertNotNull($account->picture->fid, 'User picture object has a FID after user load.');
$this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user load.');
user_save($account);
// Verify that the user save does not destroy the user picture object.
$this->assertTrue(is_object($account->picture), 'User picture object is valid after user save.');
$this->assertNotNull($account->picture->fid, 'User picture object has a FID after user save.');
$this->assertTrue(is_file($account->picture->uri), 'File is located in proper directory after user save.');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment