Skip to content

Instantly share code, notes, and snippets.

@kurowski
Created November 21, 2016 21:49
Show Gist options
  • Save kurowski/925ca878c2ca21bcfac44b4d266badc4 to your computer and use it in GitHub Desktop.
Save kurowski/925ca878c2ca21bcfac44b4d266badc4 to your computer and use it in GitHub Desktop.
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 470ddfc..086fd95 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -707,18 +707,21 @@ function node_user_cancel($edit, $account, $method) {
* Implements hook_ENTITY_TYPE_predelete() for user entities.
*/
function node_user_predelete($account) {
- // Delete nodes (current revisions).
- // @todo Introduce node_mass_delete() or make node_mass_update() more flexible.
- $nids = \Drupal::entityQuery('node')
- ->condition('uid', $account->id())
- ->execute();
- entity_delete_multiple('node', $nids);
// Delete old revisions.
$storage_controller = \Drupal::entityManager()->getStorage('node');
$revisions = $storage_controller->userRevisionIds($account);
foreach ($revisions as $revision) {
- node_revision_delete($revision);
+ $node = entity_revision_load('node', $revision);
+ if (!$node->isDefaultRevision()) {
+ node_revision_delete($revision);
+ }
}
+ // Delete nodes (current revisions).
+ // @todo Introduce node_mass_delete() or make node_mass_update() more flexible.
+ $nodes = $storage_controller->loadByProperties([
+ 'uid' => $account->id()
+ ]);
+ $storage_controller->delete($nodes);
}
/**
@kurowski
Copy link
Author

My Behat tests are failing with "Default revision can not be deleted (Drupal\Core\Entity\EntityStorageException)".

This patch fixes it, but I'm not yet sure whether this is the correct approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment