Skip to content

Commit f36e6fb

Browse files
committed
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.
1 parent 2eefbd2 commit f36e6fb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

app/Console/Commands/CreateAdminCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function handle(UserRepo $userRepo): int
6060
if ($initialAdminOnly) {
6161
$handled = $this->handleInitialAdminIfExists($userRepo, $details, $shouldGeneratePassword, $adminRole);
6262
if ($handled !== null) {
63-
return $handled ? 0 : 1;
63+
return $handled;
6464
}
6565
}
6666

@@ -87,16 +87,16 @@ public function handle(UserRepo $userRepo): int
8787

8888
/**
8989
* Handle updates to the original admin account if it exists.
90-
* Returns true if it's been successfully handled, false if unsuccessful, or null if not handled.
90+
* Returns an int return status if handled, otherwise returns null if not handled (new user to be created).
9191
*/
92-
protected function handleInitialAdminIfExists(UserRepo $userRepo, array $data, bool $generatePassword, Role $adminRole): bool|null
92+
protected function handleInitialAdminIfExists(UserRepo $userRepo, array $data, bool $generatePassword, Role $adminRole): int|null
9393
{
9494
$defaultAdmin = $userRepo->getByEmail('[email protected]');
9595
if ($defaultAdmin && $defaultAdmin->hasSystemRole('admin')) {
9696
if ($defaultAdmin->email !== $data['email'] && $userRepo->getByEmail($data['email']) !== null) {
9797
$this->error("Could not create admin account.");
9898
$this->error("An account with the email address \"{$data['email']}\" already exists.");
99-
return false;
99+
return 1;
100100
}
101101

102102
$userRepo->updateWithoutActivity($defaultAdmin, $data, true);
@@ -106,10 +106,10 @@ protected function handleInitialAdminIfExists(UserRepo $userRepo, array $data, b
106106
$this->info("The default admin user has been updated with the provided details!");
107107
}
108108

109-
return true;
109+
return 0;
110110
} else if ($adminRole->users()->count() > 0) {
111111
$this->warn('Non-default admin user already exists. Skipping creation of new admin user.');
112-
return true;
112+
return 2;
113113
}
114114

115115
return null;

tests/Commands/CreateAdminCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function test_initial_option_does_not_update_if_only_non_default_admin_ex
109109
'--password' => 'testing-7',
110110
'--initial' => true,
111111
])->expectsOutput('Non-default admin user already exists. Skipping creation of new admin user.')
112-
->assertExitCode(0);
112+
->assertExitCode(2);
113113

114114
$defaultAdmin->refresh();
115115

@@ -156,7 +156,7 @@ public function test_initial_rerun_does_not_error_but_skips()
156156
'--password' => 'testing-7',
157157
'--initial' => true,
158158
])->expectsOutput("Non-default admin user already exists. Skipping creation of new admin user.")
159-
->assertExitCode(0);
159+
->assertExitCode(2);
160160
}
161161

162162
public function test_initial_option_creation_errors_if_email_already_exists()

0 commit comments

Comments
 (0)