mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
fix: validate required cli install args (#4093)
This commit is contained in:
@@ -13,6 +13,7 @@ use Flarum\Install\AdminUser;
|
|||||||
use Flarum\Install\BaseUrl;
|
use Flarum\Install\BaseUrl;
|
||||||
use Flarum\Install\DatabaseConfig;
|
use Flarum\Install\DatabaseConfig;
|
||||||
use Flarum\Install\Installation;
|
use Flarum\Install\Installation;
|
||||||
|
use Flarum\Install\ValidationFailed;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
@@ -50,13 +51,13 @@ class UserDataProvider implements DataProviderInterface
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (in_array($driver, ['mysql', 'pgsql'])) {
|
if (in_array($driver, ['mysql', 'pgsql'])) {
|
||||||
$host = $this->ask('Database host (required):');
|
$host = $this->ask('Database host (required):', required: true);
|
||||||
|
|
||||||
if (Str::contains($host, ':')) {
|
if (Str::contains($host, ':')) {
|
||||||
list($host, $port) = explode(':', $host, 2);
|
list($host, $port) = explode(':', $host, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->ask('Database user (required):');
|
$user = $this->ask('Database user (required):', required: true);
|
||||||
$password = $this->secret('Database password:');
|
$password = $this->secret('Database password:');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ class UserDataProvider implements DataProviderInterface
|
|||||||
$driver,
|
$driver,
|
||||||
$host ?? null,
|
$host ?? null,
|
||||||
intval($port),
|
intval($port),
|
||||||
$this->ask('Database name (required):'),
|
$this->ask('Database name (required):', required: true),
|
||||||
$user ?? null,
|
$user ?? null,
|
||||||
$password ?? null,
|
$password ?? null,
|
||||||
$this->ask('Prefix:')
|
$this->ask('Prefix:')
|
||||||
@@ -83,7 +84,7 @@ class UserDataProvider implements DataProviderInterface
|
|||||||
return new AdminUser(
|
return new AdminUser(
|
||||||
$this->ask('Admin username (Default: admin):', 'admin'),
|
$this->ask('Admin username (Default: admin):', 'admin'),
|
||||||
$this->askForAdminPassword(),
|
$this->askForAdminPassword(),
|
||||||
$this->ask('Admin email address (required):')
|
$this->ask('Admin email address (required):', required: true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,10 +120,20 @@ class UserDataProvider implements DataProviderInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ask(string $question, ?string $default = null): mixed
|
private function ask(string $question, ?string $default = null, bool $required = false): mixed
|
||||||
{
|
{
|
||||||
$question = new Question("<question>$question</question> ", $default);
|
$question = new Question("<question>$question</question> ", $default);
|
||||||
|
|
||||||
|
if ($required) {
|
||||||
|
$question->setValidator(function ($value) {
|
||||||
|
if (empty($value)) {
|
||||||
|
throw new ValidationFailed('This value is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return $this->questionHelper->ask($this->input, $this->output, $question);
|
return $this->questionHelper->ask($this->input, $this->output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user