3 namespace BookStack\Console\Commands;
6 use BookStack\Repos\UserRepo;
7 use Illuminate\Console\Command;
9 class DeleteUsers extends Command
13 * The name and signature of the console command.
17 protected $signature = 'bookstack:delete-users';
24 * The console command description.
28 protected $description = 'Delete users that are not "admin" or system users.';
30 public function __construct(User $user, UserRepo $userRepo)
33 $this->userRepo = $userRepo;
34 parent::__construct();
37 public function handle()
39 $confirm = $this->ask('This will delete all users from the system that are not "admin" or system users. Are you sure you want to continue? (Type "yes" to continue)');
41 if (strtolower(trim($confirm)) === 'yes') {
42 $totalUsers = $this->user->count();
43 $users = $this->user->where('system_name', '=', null)->with('roles')->get();
44 foreach ($users as $user) {
45 if ($user->hasSystemRole('admin')) {
46 // don't delete users with "admin" role
49 $this->userRepo->destroy($user);
52 $this->info("Deleted $numDeleted of $totalUsers total users.");
54 $this->info('Exiting...');