Problem/Motivation

When running the operation, a php error is generated:

Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 141 of /var/www/html/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php)

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joey-santiago created an issue.

omkar_yewale’s picture

Hi @joey-santiago,
While reviewing the MR, I realized there were a few possible changes we can do.

/user_delete_reassign/src/Form/UserDeleteReassignConfigForm.php

$roles = user_role_names(TRUE);
foreach ($roles as $id => $val) {
  $roles[$id] = Html::escape($val);
}

To

use Drupal\user\Entity\Role;

$roles = Role::loadMultiple();
foreach ($roles as $id => $role) {
  if ($id !== 'anonymous') {
    $roles[$id] = Html::escape($role->label());
  }
}
/user_delete_reassign/user_delete_reassign.module
$nodes = \Drupal::entityQuery('node')
    ->condition('uid', $account->id())
    ->execute();
node_mass_update($nodes, ['uid' => $new_user->id()], NULL, TRUE);

To

use Drupal\Core\Entity\EntityTypeManagerInterface;

$nodeStorage = \Drupal::service('entity_type.manager')->getStorage('node');
$nodes = $nodeStorage->getQuery()
    ->condition('uid', $account->id())
    ->accessCheck(FALSE)
    ->execute();
foreach ($nodes as $node_id) {
  $node = $nodeStorage->load($node_id);
  $node->set('uid', $new_user->id());
  $node->save();
}