Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better feedback on bolt:setup errors #1551

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class SetupCommand extends Command
/** @var Connection */
private $connection;

/** @var array */
private $errors = [];

public function __construct(Connection $connection)
{
$this->connection = $connection;
Expand Down Expand Up @@ -47,35 +50,50 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$command = $this->getApplication()->find('doctrine:database:create');
$exitCode += $command->run(new ArrayInput($options), $output);
$exitCode = $command->run(new ArrayInput($options), $output);
$this->processExitCode($exitCode, 'An error occurred when creating the database.');

$command = $this->getApplication()->find('doctrine:schema:create');
$exitCode += $command->run(new ArrayInput([]), $output);
$exitCode = $command->run(new ArrayInput([]), $output);
$this->processExitCode($exitCode, 'An error occurred when creating the database schema.');

$command = $this->getApplication()->find('bolt:reset-secret');
$exitCode += $command->run(new ArrayInput([]), $output);
$exitCode = $command->run(new ArrayInput([]), $output);
$this->processExitCode($exitCode, 'An error occurred while resetting APP_SECRET in the .env file.');

$command = $this->getApplication()->find('bolt:add-user');
$commandInput = new ArrayInput(['--admin' => true]);
$exitCode += $command->run($commandInput, $output);
$exitCode = $command->run($commandInput, $output);
$this->processExitCode($exitCode, 'An error occurred when creating the new Bolt user.');

// Unless either `--no-fixtures` or `--fixtures` was set, we prompt the user for it.
if (! $input->getOption('no-fixtures')) {
if ($input->getOption('fixtures') || $io->confirm('Add fixtures (dummy content) to the Database?', true)) {
$command = $this->getApplication()->find('doctrine:fixtures:load');
$commandInput = new ArrayInput(['--append' => true]);
$exitCode += $command->run($commandInput, $output);
$exitCode = $command->run($commandInput, $output);
$this->processExitCode($exitCode, 'An error occurred while adding the fixtures (dummy content) to the database.');
}
}

$io->newLine();

if ($exitCode !== 0) {
if (! empty($this->errors)) {
$io->error('Some errors occurred while setting up Bolt.');
foreach ($this->errors as $error) {
$io->warning($error);
}
} else {
$io->success('Bolt was set up successfully! Start a web server, and open your Bolt site in a browser.');
}

return 0;
}

private function processExitCode(int $exitCode, string $message): void
{
if ($exitCode) {
$this->errors[] = $message;
}
}
}