3 namespace BookStack\Console\Commands;
6 use BookStack\Repos\UserRepo;
7 use Illuminate\Console\Command;
9 class DeleteUsers extends Command{
12 * The name and signature of the console command.
16 protected $signature = 'bookstack:delete-users';
23 * The console command description.
27 protected $description = 'Delete users that are not "admin" or system users.';
29 public function __construct(User $user, UserRepo $userRepo)
32 $this->userRepo = $userRepo;
33 parent::__construct();
36 public function handle()
38 $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)');
40 if (strtolower(trim($confirm)) === 'yes')
42 $totalUsers = User::count();
43 $users = $this->user->where('system_name', '=', null)->with('roles')->get();
44 foreach ($users as $user)
46 if ($user->hasRole('admin'))
48 // don't delete users with "admin" role
51 $this->userRepo->destroy($user);
54 $this->info("Deleted $numDeleted of $totalUsers total users.");
58 $this->info('Exiting...');