1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-10-26 17:31:27 +03:00

Commands: Updated create admin skip return

Return status for skipped --initial creation will now return 2, so that
it can be identified seperate from a creation and from an error.
This commit is contained in:
Dan Brown
2025-08-07 13:16:49 +01:00
parent 2eefbd21c1
commit f36e6fb929
2 changed files with 8 additions and 8 deletions

View 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;

View 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()