Comments are lost when user is deleted

Created on 18 August 2023, over 1 year ago
Updated 2 September 2023, over 1 year ago

Colleagues, hello!

Problem/Motivation

When programmatically deleting a user, all his previously left comments are deleted.

Steps to reproduce

Run the following code in a custom module:

/**
 * Implementation of hook_cron()
 */
function modulename_cron()
{

  $db = \Drupal::database();

  $cron = new Cron();

  $accounts = $db->query(<SQL>)->fetchAll();

  foreach ($accounts as $a) {
    $account = User::load($a->uid);
    $account->delete();
  }

}

Or is it enough to run the drush command:

vendor/bin/drush php:eval "Drupal\user\Entity\User::load(<User_ID>)->delete()"

Proposed resolution

Most likely for entities hook_user_cancel is not implemented

🐛 Bug report
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024