3 namespace BookStack\Console\Commands;
5 use BookStack\Auth\User;
6 use BookStack\Auth\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') {
41 $totalUsers = $this->user->count();
42 $users = $this->user->where('system_name', '=', null)->with('roles')->get();
43 foreach ($users as $user) {
44 if ($user->hasSystemRole('admin')) {
45 // don't delete users with "admin" role
48 $this->userRepo->destroy($user);
51 $this->info("Deleted $numDeleted of $totalUsers total users.");
53 $this->info('Exiting...');