Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
test case:
1. create user
2. upload picture
3. cancel account or use user_delete()
picture not delete from file system and db tables file_managed/file_usage, also file_managed.status still "1"
Comment | File | Size | Author |
---|---|---|---|
#20 | user-1398616-20.patch | 2.96 KB | duellj |
#18 | user-1398616-18.patch | 2.94 KB | duellj |
#13 | user-1398616-13-D7.patch | 2.37 KB | wedge |
#7 | user-1398616-7.patch | 2.45 KB | duellj |
#4 | user-1398616-4.patch | 2.67 KB | duellj |
Comments
Comment #0.0
xandeadx CreditAttribution: xandeadx commentedchange Description
Comment #1
star-szrI was able to reproduce this on a fresh 7.10 install.
1. Create new user via admin account.
2. Add a picture to the user's account via admin account or the user account itself.
3. Cancel the user's account using the "Delete the account and its content." option.
The user picture remains in the file system and in the file_managed and file_usage tables.
Possibly related to http://drupal.org/node/1378092.
Comment #2
star-szrComment #3
tsphethean CreditAttribution: tsphethean commentedI've tested this issue after applying the patch from http://drupal.org/node/1378092 and it does not resolve the issue - the difference is that this is via the cancellation form which calls user_delete whereas 1378092 is on the user_save call when saving user profile.
I'd be interested in opinions on a couple of approaches to this:
1. Modify user.module user_delete function to directly call file_usage_delete and file_delete if there is a profile picture attached to the user account (which would solve this individual issue)
2. As there would appear to be the possibility that any files which belong to the user may not be deleted when the user is deleted via user_delete_multiple, would a better approach be to implement hook_user_delete in the file module (file_user_delete) so that the file module will respond to the user delete by deleting any files associated with them?
As an aside - and might need a seperate issue, as far as I can see the code for user_cancel applies the same to "Delete user and all their content" and "Delete user and assign their content to anonymous". Do we need to cover this scenario too?
Comment #4
duellj CreditAttribution: duellj commentedIt makes the most sense that file deletion would be handled in file.module by a hook_user_predelete(), since user_delete() concerns itself only with deleting users from the {users*} tables (and {authmap}), whereas other modules are responsible for handling the deletion of their user data (e.g. node_user_predelete() and comment_user_predelete()).
Since a picture can't be added to the anonymous user (and thus can't be deleted), it doesn't make sense to transfer the picture over to the anonymous user if the ""Delete user and assign their content to anonymous" option is used.
Attached is a patch that deletes the picture when a user account is deleted, as well as adds a test for testing if a picture actually does get deleted when a user account is deleted.
This should probably be backported to 7.x too, no?
Comment #5
tsphethean CreditAttribution: tsphethean commentedPatch looks sensible, and better than my idea!
I've tested in my dev environment and confirmed that the file is deleted from the file system and from the database.
Comment #6
webchickHuh. I totally forgot there was a hook_user_predelete(). That seems like a sane fix to me.
Looks like this needs a re-roll, however.
Comment #7
duellj CreditAttribution: duellj commentedThanks webchick! Rerolled patch against current HEAD.
Comment #8
duellj CreditAttribution: duellj commented#7: user-1398616-7.patch queued for re-testing.
Comment #9
tascd7 version would be nice here indeed...
Comment #10
tstoecklerMinor: but the drupalGet() is unnecessary if you put the path in drupalPost().
Don't know if it is worth holding this up on that, since it is really aesthetic.
If not, this is RTBC.
Comment #11
tstoecklerOops, wanted to leave at needs review.
Comment #12
Tor Arne Thune CreditAttribution: Tor Arne Thune commentedAlso, on the next reroll "Test" needs to be changed to "Tests"
Comment #13
wedge CreditAttribution: wedge commentedI needed this for D7. Rerolled using hook_user_delete since hook_user_predelete doesn't seem to be available in D7.
Also include suggestions from comment #10 and #12. The test passes here.
Comment #15
barraponto CreditAttribution: barraponto commentedDuplicates #1378092: User pictures are not removed properly I guess. @wedge?
Comment #16
wedge CreditAttribution: wedge commented@barraponto Not really a duplicate, and since that issue is closed I guess we can continue here? See explanation in comment #3.
Comment #17
duellj CreditAttribution: duellj commented#7: user-1398616-7.patch queued for re-testing.
Comment #18
duellj CreditAttribution: duellj commentedHere's a patch rerolled against head that makes the changes in #10 and #12. file_usage_delete has also been removed from core, so made the necessary changes over to the new api.
Comment #20
duellj CreditAttribution: duellj commentedWhoops, forgot to convert the variable_set to the new config system. Tests should pass now.
Comment #21
firfin CreditAttribution: firfin commentedFixing this might be a solution for #1568098: Delete Pictures on Feeds delete. And possibly #1433188: Add support for User Picture mapping field.
Currently a blocker for inclusion of 'feeds_user_picture' in Feeds.
I will be testing this patch soon I hope.
Comment #21.0
firfin CreditAttribution: firfin commentedchange Description
Comment #24
star-szr@alansaviolobo - I can only speak for myself but I'd ask that you please stop re-testing all these old issues, a bot could go through all these issues and click re-test on the last patch so I don't think it's very productive. A better use of your time might be for example to test this issue to see if it still applies to the latest 8.0.x, and do some triage.
Contributor task: Verify a reported issue
Comment #25
swentel CreditAttribution: swentel commentedUser picture is a field now, so this only applies to D7 now.