Remove User Account Picture on Account Cancel

by Prasanth R   Last Updated June 19, 2018 10:07 AM

Am cancelling out user account(Delete the account and make its content belong to the Anonymous user) using services module.

Hence followed this query and updated in the user_resource.inc

function _user_resource_cancel($uid) {
  if ($uid == 1) {
    return services_error(t('The admin user cannot be canceled.'), 403);
  }
  $account = user_load($uid);
  $fid = $account->picture->fid;
  // Load the file object
  $file = file_load($fid);
  // delete profile photo from.
  file_delete($file);
  // Unset the image object (my case it's 'picture')
  unset($account->picture);
  // Save the user
  user_save($account);
}

I can able to unset the picture, but the file still exists in the file system so as DB entry in the file_managed table & users table

fid in users table is updated to 0 after account cancellation

enter image description here enter image description here

Tags : 7 users services


Related Questions



Register a user through URL in drupal 8

Updated March 29, 2017 16:07 PM

GET list of all roles on Drupal 8 via REST

Updated July 02, 2018 15:07 PM

Missing required argument name in login

Updated August 17, 2016 08:04 AM

Services Module Unable To Update User Fields

Updated September 27, 2016 09:03 AM