]> BookStack Code Mirror - bookstack/commitdiff
Commands: Updated create admin skip return admin_command_updates 5749/head
authorDan Brown <redacted>
Thu, 7 Aug 2025 12:16:49 +0000 (13:16 +0100)
committerDan Brown <redacted>
Thu, 7 Aug 2025 12:16:49 +0000 (13:16 +0100)
Return status for skipped --initial creation will now return 2, so that
it can be identified seperate from a creation and from an error.

app/Console/Commands/CreateAdminCommand.php
tests/Commands/CreateAdminCommandTest.php

index 520f0822a669c6a13845c86ba568d5f583b497b5..bf72553f72a3018e49cc511d7bc3124f3bc3a250 100644 (file)
@@ -60,7 +60,7 @@ class CreateAdminCommand extends Command
         if ($initialAdminOnly) {
             $handled = $this->handleInitialAdminIfExists($userRepo, $details, $shouldGeneratePassword, $adminRole);
             if ($handled !== null) {
-                return $handled ? 0 : 1;
+                return $handled;
             }
         }
 
@@ -87,16 +87,16 @@ class CreateAdminCommand extends Command
 
     /**
      * Handle updates to the original admin account if it exists.
-     * Returns true if it's been successfully handled, false if unsuccessful, or null if not handled.
+     * Returns an int return status if handled, otherwise returns null if not handled (new user to be created).
      */
-    protected function handleInitialAdminIfExists(UserRepo $userRepo, array $data, bool $generatePassword, Role $adminRole): bool|null
+    protected function handleInitialAdminIfExists(UserRepo $userRepo, array $data, bool $generatePassword, Role $adminRole): int|null
     {
         $defaultAdmin = $userRepo->getByEmail('admin@admin.com');
         if ($defaultAdmin && $defaultAdmin->hasSystemRole('admin')) {
             if ($defaultAdmin->email !== $data['email'] && $userRepo->getByEmail($data['email']) !== null) {
                 $this->error("Could not create admin account.");
                 $this->error("An account with the email address \"{$data['email']}\" already exists.");
-                return false;
+                return 1;
             }
 
             $userRepo->updateWithoutActivity($defaultAdmin, $data, true);
@@ -106,10 +106,10 @@ class CreateAdminCommand extends Command
                 $this->info("The default admin user has been updated with the provided details!");
             }
 
-            return true;
+            return 0;
         } else if ($adminRole->users()->count() > 0) {
             $this->warn('Non-default admin user already exists. Skipping creation of new admin user.');
-            return true;
+            return 2;
         }
 
         return null;
index fa1329ad322b643fdffe6341fc00c18c16fd3378..f389dd94235b13b986caf853ffdf9cb263a5d935 100644 (file)
@@ -109,7 +109,7 @@ class CreateAdminCommandTest extends TestCase
             '--password' => 'testing-7',
             '--initial' => true,
         ])->expectsOutput('Non-default admin user already exists. Skipping creation of new admin user.')
-            ->assertExitCode(0);
+            ->assertExitCode(2);
 
         $defaultAdmin->refresh();
 
@@ -156,7 +156,7 @@ class CreateAdminCommandTest extends TestCase
             '--password' => 'testing-7',
             '--initial' => true,
         ])->expectsOutput("Non-default admin user already exists. Skipping creation of new admin user.")
-            ->assertExitCode(0);
+            ->assertExitCode(2);
     }
 
     public function test_initial_option_creation_errors_if_email_already_exists()