NOW MANAGED ON CODEBERG
Commands: Updated create admin skip return
Dan Brownf36e6fb929d5
diff --git a/app/Console/Commands/CreateAdminCommand.php b/app/Console/Commands/CreateAdminCommand.phpindex 520f0822a..bf72553f7 100644--- a/app/Console/Commands/CreateAdminCommand.php+++ b/app/Console/Commands/CreateAdminCommand.php@@ -60,7 +60,7 @@ class CreateAdminCommand extends Commandif ($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('[email protected]');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;diff --git a/tests/Commands/CreateAdminCommandTest.php b/tests/Commands/CreateAdminCommandTest.phpindex fa1329ad3..f389dd942 100644--- a/tests/Commands/CreateAdminCommandTest.php+++ b/tests/Commands/CreateAdminCommandTest.php@@ -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()