]> BookStack Code Mirror - bookstack/blobdiff - app/Console/Commands/DeleteUsers.php
Added 'Sort Book' action to chapters
[bookstack] / app / Console / Commands / DeleteUsers.php
index 8829d39923a58b4911de1fde0d57ccfd65adabc7..bc7263c774228b13cd7c625c10782baee0ed3df0 100644 (file)
@@ -2,12 +2,12 @@
 
 namespace BookStack\Console\Commands;
 
-use BookStack\User;
-use BookStack\Repos\UserRepo;
+use BookStack\Auth\User;
+use BookStack\Auth\UserRepo;
 use Illuminate\Console\Command;
 
-class DeleteUsers extends Command{
-
+class DeleteUsers extends Command
+{
     /**
      * The name and signature of the console command.
      *
@@ -15,8 +15,6 @@ class DeleteUsers extends Command{
      */
     protected $signature = 'bookstack:delete-users';
 
-    protected $user;
-
     protected $userRepo;
 
     /**
@@ -24,11 +22,10 @@ class DeleteUsers extends Command{
      *
      * @var string
      */
-    protected $description = 'Delete users that are not "admin" or system users.';
+    protected $description = 'Delete users that are not "admin" or system users';
 
-    public function __construct(User $user, UserRepo $userRepo)
+    public function __construct(UserRepo $userRepo)
     {
-        $this->user = $user;
         $this->userRepo = $userRepo;
         parent::__construct();
     }
@@ -37,26 +34,20 @@ class DeleteUsers extends Command{
     {
         $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)');
         $numDeleted = 0;
-        if (strtolower(trim($confirm)) === 'yes')
-        {
-            $totalUsers = $this->user->count();
-            $users = $this->user->where('system_name', '=', null)->with('roles')->get();
-            foreach ($users as $user)
-            {
-                if ($user->hasSystemRole('admin'))
-                {
+        if (strtolower(trim($confirm)) === 'yes') {
+            $totalUsers = User::query()->count();
+            $users = User::query()->whereNull('system_name')->with('roles')->get();
+            foreach ($users as $user) {
+                if ($user->hasSystemRole('admin')) {
                     // don't delete users with "admin" role
                     continue;
                 }
                 $this->userRepo->destroy($user);
-                ++$numDeleted;
+                $numDeleted++;
             }
             $this->info("Deleted $numDeleted of $totalUsers total users.");
-        }
-        else
-        {
+        } else {
             $this->info('Exiting...');
         }
     }
-
 }