Commit 2740e709 authored by catch's avatar catch
Browse files

Issue #2844293 by swentel: Manually calling $account->delete() will throw an...

Issue #2844293 by swentel: Manually calling $account->delete() will throw an exception if the user has nodes in an anonymous environment with node access enabled
parent 890bb76f
...@@ -711,6 +711,7 @@ function node_user_predelete($account) { ...@@ -711,6 +711,7 @@ function node_user_predelete($account) {
// @todo Introduce node_mass_delete() or make node_mass_update() more flexible. // @todo Introduce node_mass_delete() or make node_mass_update() more flexible.
$nids = \Drupal::entityQuery('node') $nids = \Drupal::entityQuery('node')
->condition('uid', $account->id()) ->condition('uid', $account->id())
->accessCheck(FALSE)
->execute(); ->execute();
entity_delete_multiple('node', $nids); entity_delete_multiple('node', $nids);
// Delete old revisions. // Delete old revisions.
......
...@@ -594,4 +594,20 @@ function testMassUserCancelByAdmin() { ...@@ -594,4 +594,20 @@ function testMassUserCancelByAdmin() {
$this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.'); $this->assertTrue($user1->isActive(), 'User #1 still exists and is not blocked.');
} }
/**
* Tests user cancel with node access.
*/
function testUserDeleteWithContentAndNodeAccess() {
\Drupal::service('module_installer')->install(['node_access_test']);
// Rebuild node access.
node_access_rebuild();
$account = $this->drupalCreateUser(['access content']);
$node = $this->drupalCreateNode(['type' => 'page', 'uid' => $account->id()]);
$account->delete();
$load2 = \Drupal::entityTypeManager()->getStorage('node')->load($node->id());
$this->assertTrue(empty($load2));
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment