http://api.drupal.org/api/function/user_file_delete/7

Hooks don't get fired, caches don't get cleared

CommentFileSizeAuthor
#1 814874-user-file-delete.patch956 bytesmr.baileys
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr.baileys’s picture

Status: Active » Needs review
FileSize
956 bytes

Patch attached to replace the current query with a call to user_save.

moshe weitzman’s picture

Sure. But is there any chance of infinite loop. Could user_file_delete get called during a user_save()?

drewish’s picture

Version: 7.x-dev » 8.x-dev

Guessing this is a problem in 8.x. The current method has some performance problems you get a query on the user table when any file is deleted. We've got 500,000 users on a site I'm working on and file deletions are crawling. I wonder if we could look at the {file_usage} data instead.

drewish’s picture

Oh... I guess that's because there's no index on picture.

drewish’s picture

tstoeckler’s picture

Re #2: Good guess, @moshe! :)
Here's user_save():

        // Delete the previous picture if it was deleted or replaced.
        if (!empty($account->original->picture->fid)) {
          file_usage_delete($account->original->picture, 'user', 'user', $account->uid);
          file_delete($account->original->picture);
        }
kscheirer’s picture

#1: 814874-user-file-delete.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 814874-user-file-delete.patch, failed testing.

kscheirer’s picture

Retesting against latest HEAD since it has been over a year.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Version: 8.2.x-dev » 7.x-dev
Issue summary: View changes
Issue tags: +user picture

User picture is now a field, it is not managed by the user table in D8.

Changing to Drupal 7

amit0212’s picture

- use patch
patch
- Fresh install
- Go to your account and upload a profile picture
- Execute a bit of PHP...

$account = user_load(1);
user_save($account);

- No more profile picture.

I will work on a patch, but feel free to write a new test if anyone has time.

dpi’s picture

- use patch
patch

The issue where this patch comes from already addresses #935592: User picture is deleted after calls to user_save().

This issue is about invoking entity hooks.

If your pictures are still getting deleted due to user_save(), then you should re-open the other issue/open new issue.