Closed (fixed)
Project:
Flag
Version:
5.2.x-dev
Component:
Flag core
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
16 May 2015 at 21:10 UTC
Updated:
12 Nov 2026 at 08:35 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
michaellenahan commentedI agree ... cancelling the user account is not the same as deleting it.
Comment #2
michaellenahan commentedHere's an initial, very rudimentary patch.
A more complete patch should take into account the $method argument.
For the various possibilities of the $method argument, and their meanings, see: https://api.drupal.org/api/drupal/modules%21user%21user.pages.inc/functi...
See https://api.drupal.org/api/drupal/modules%21comment%21comment.module/fun... for an example that uses a switch statement to handle the various methods differently.
Comment #3
joachim commented> "the module should either do nothing, unpublish content, or anonymize content" ... it should not be deleting user data.
Taking these options one by one:
- do nothing
That leaves flag counts that look incorrect.
- unpublish content
Can't do that, there is no concept of a flagging being unpublished
- anonymize content
We don't have a session ID we can set on the flaggings, and anon flagging might not be enabled.
Comment #4
casey commentedComment #5
eelkeblokI am seeing this functionality actually causing issues on cancelling a user that has a lot of flaggings. I think blanket deleting all flaggings whenever hook_user_cancel is called is not the right approach;
That may also end up being less work, because by then a lot of content created by the user may have been deleted as well, and thereby also any associated flaggings, through the implementation of hook_entity_predelete() (which is likely to have happened in a batch, for properly implemented cancellation methods).This tells me there is actually no need for a hook_user_cancel() implementation in Flag, and it is in fact only causing problems.
Of course, please tell me if I'm missing something. Setting back to "Needs review" to raise the awareness again.
Edit: actually, the idea that a lot of flaggings would have been deleted by deleting the user's content is probably invalid, as flaggings mostly would apply to content created by others.
Comment #6
eelkeblokBTW, if it is determined deleting flaggings is the right approach in some cases (maybe when the user is deleted but the content is re-assigned, so there will not actually be many content-related unflaggings) , it would be a good idea to do so by adding to the cancellation batch (it is not a very well documented feature that when hook_user_cancel() is called, there is actually a batch standing by which can be added to by calling batch_set() with an array that contains some extra operations). We may still get in trouble when trying to delete the flaggings at the very end when the user is deleted and there is still a large number left, at that point.
Comment #8
eelkeblokOver four years onward, I needed a more nuanced implementation, here's a stab at it. This only deletes flaggings when re-assigning content to the anonymous user (deleting a user will already call the existing pre-delete hook). Also, it checks the number of flaggings to remove to a threshold, and will create a queue to delete the flaggings in batches when it exceeds the threshold. The threshold itself is obviously up for debate, maybe the current 20 is a bit too convervative.
Comment #9
ivnishComment #10
eelkeblokCan you elaborate on the reason this needs work? AFAICT the merge request is mergeable.
Comment #11
ivnishSorry, I took your message #8 as meaning that the MR needs some work.
Comment #12
ivnishAlso, needs tests
Comment #13
eelkeblokAh, no, it was meant to say I adjusted the MR. Fair enough to get some tests.
Comment #16
deaom commentedI'm not really sure what tests to add here, but did add one for admin UI and one for service call. Just to test the user and flags actually get removed. Could not cherry pick the commit from 8.x. as there were some changes in FlagService in the 5.x branch, hopefully resolved conflicts correctly. Needs review.
Comment #19
idebr commentedComment #21
benstallings commentedComment #22
idebr commented#19 still applies
Comment #25
idebr commentedThe merge request currently has code changes for two issues:
In order to make the issue easier to review, let's split up these issues. The queue implementation is now split into #3633556: Use a queue when deleting a large set of flaggings
Comment #26
idebr commentedComment #27
anybodyNice work. We even have a test!
Comment #28
ivnishComment #30
ivnishThanks! Merged!