public function UserDeleteController::getUserToDelete in Delete all 2.x
Same name and namespace in other branches
- 8 src/Controller/UserDeleteController.php \Drupal\delete_all\Controller\UserDeleteController::getUserToDelete()
Get uids of the users to delete.
Parameters
array $roles: Array of roles.
Return value
array Array of uids of users to delete.
File
- src/
Controller/ UserDeleteController.php, line 21
Class
- UserDeleteController
- Returns responses for devel module routes.
Namespace
Drupal\delete_all\ControllerCode
public function getUserToDelete($roles = FALSE) {
$users_to_delete = [];
// Get the uids of users to delete by role.
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);
// Exclude anonymous users and root.
$users_to_delete = array_diff($users_to_delete, [
0,
1,
]);
}
}
}
else {
$users_to_delete = FALSE;
}
return $users_to_delete;
}