3 namespace BookStack\Console\Commands;
5 use BookStack\Users\Models\User;
6 use BookStack\Users\UserRepo;
7 use Illuminate\Console\Command;
9 class DeleteUsersCommand extends Command
12 * The name and signature of the console command.
16 protected $signature = 'bookstack:delete-users';
19 * The console command description.
23 protected $description = 'Delete users that are not "admin" or system users';
26 * Execute the console command.
28 public function handle(UserRepo $userRepo): int
30 $this->warn('This will delete all users from the system that are not "admin" or system users.');
31 $confirm = $this->confirm('Are you sure you want to continue?');
37 $totalUsers = User::query()->count();
39 $users = User::query()->whereNull('system_name')->with('roles')->get();
41 foreach ($users as $user) {
42 if ($user->hasSystemRole('admin')) {
43 // don't delete users with "admin" role
46 $userRepo->destroy($user);
50 $this->info("Deleted $numDeleted of $totalUsers total users.");