UserDeleteController.php in Delete all 2.x
File
src/Controller/UserDeleteController.php
View source
<?php
namespace Drupal\delete_all\Controller;
use Drupal\delete_all\Controller\DeleteControllerBase;
class UserDeleteController extends DeleteControllerBase {
public function getUserToDelete($roles = FALSE) {
$users_to_delete = [];
if ($roles !== FALSE) {
foreach ($roles as $role) {
if (isset($role) && !empty($role)) {
$uids = $this->connection
->select('user__roles', 'ur')
->fields('ur', [
'entity_id',
])
->condition('roles_target_id', $role)
->execute()
->fetchCol('uid');
$users_to_delete = array_merge($users_to_delete, $uids);
$users_to_delete = array_diff($users_to_delete, [
0,
1,
]);
}
}
}
else {
$users_to_delete = FALSE;
}
return $users_to_delete;
}
public function getUserDeleteBatch($users_to_delete = FALSE) {
$batch = [
'operations' => [
[
'delete_all_users_batch_delete',
[
$users_to_delete,
],
],
],
'finished' => 'delete_all_users_batch_delete_finished',
'title' => $this
->t('Deleting users'),
'init_message' => $this
->t('User deletion is starting.'),
'progress_message' => $this
->t('Deleting users...'),
'error_message' => $this
->t('User deletion has encountered an error.'),
];
return $batch;
}
}