diff options
author | David Rothstein <drothstein@gmail.com> | 2014-11-04 01:34:07 -0500 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2014-11-04 01:34:07 -0500 |
commit | 037848ad555fd5fe7fad45df5e720f03eaf8df04 (patch) | |
tree | 531242f5c24b350b97c97584fee3b3c2ad79d5c1 /modules/user | |
parent | d7ea3ba5994c5a4d69bd5661972637d094536b99 (diff) | |
download | brdo-037848ad555fd5fe7fad45df5e720f03eaf8df04.tar.gz brdo-037848ad555fd5fe7fad45df5e720f03eaf8df04.tar.bz2 |
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().
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.module | 5 | ||||
-rw-r--r-- | modules/user/user.test | 11 |
2 files changed, 16 insertions, 0 deletions
diff --git a/modules/user/user.module b/modules/user/user.module index db1d792a2..415519148 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -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. diff --git a/modules/user/user.test b/modules/user/user.test index e2086d4fe..03f0bbcd3 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -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.'); } } |