We should avoid deleting data on user cancel.

To quote from the Drupal API https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function...

"the module should either do nothing, unpublish content, or anonymize content" ... it should not be deleting user data.

Right now we have this code removing all the flag when user cancel their account.


/**
 * Implements hook_user_cancel().
 */
function flag_user_cancel($edit, $account, $method) {
  flag_user_account_removal($account);
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

michaellenahan’s picture

Issue summary: View changes

I agree ... cancelling the user account is not the same as deleting it.

michaellenahan’s picture

Status: Active » Needs review
FileSize
374 bytes

Here'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.

joachim’s picture

Title: We should not delete flag on account cancelation » We should not delete flaggings on account cancelation
Version: 7.x-3.x-dev » 8.x-4.x-dev
Status: Needs review » Postponed (maintainer needs more info)

> "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.

casey’s picture

eelkeblok’s picture

Status: Postponed (maintainer needs more info) » Needs review

I 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;

  • Not all cancellation methods actually remove the account, blocking the account is a valid outcome as well
  • When a cancellation method actually ends up deleting the account, the implementation of hook_user_predelete() should actually take care of the deleting. 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.

eelkeblok’s picture

BTW, 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.