Check prerequisites in console installer, too

This commit is contained in:
Franz Liedke 2015-09-03 08:42:16 +02:00
parent 942db77416
commit 3c9d851889
4 changed files with 37 additions and 7 deletions

View File

@ -62,11 +62,22 @@ class InstallCommand extends Command
{ {
$this->init(); $this->init();
$this->info('Installing Flarum...'); $prerequisites = $this->getPrerequisites();
$prerequisites->check();
$errors = $prerequisites->getErrors();
$this->install(); if (empty($errors)) {
$this->info('Installing Flarum...');
$this->info('DONE.'); $this->install();
$this->info('DONE.');
} else {
$this->output->writeln(
'<error>Please fix the following errors before we can continue with the installation.</error>'
);
$this->showErrors($errors);
}
} }
protected function init() protected function init()
@ -275,4 +286,23 @@ class InstallCommand extends Command
{ {
return base_path('../config.php'); return base_path('../config.php');
} }
/**
* @return \Flarum\Install\Prerequisites\Prerequisite
*/
protected function getPrerequisites()
{
return $this->application->make('Flarum\Install\Prerequisites\Prerequisite');
}
protected function showErrors($errors)
{
foreach ($errors as $error) {
$this->info($error['message']);
if (isset($error['detail'])) {
$this->output->writeln('<comment>' . $error['detail'] . '</comment>');
}
}
}
} }

View File

@ -17,7 +17,7 @@ class PhpExtensions extends AbstractPrerequisite
foreach (['mbstring', 'pdo_mysql', 'openssl', 'json', 'gd', 'dom', 'fileinfo'] as $extension) { foreach (['mbstring', 'pdo_mysql', 'openssl', 'json', 'gd', 'dom', 'fileinfo'] as $extension) {
if (! extension_loaded($extension)) { if (! extension_loaded($extension)) {
$this->errors[] = [ $this->errors[] = [
'message' => "The <strong>$extension</strong> extension is required.", 'message' => "The $extension extension is required.",
]; ];
} }
} }

View File

@ -16,7 +16,7 @@ class PhpVersion extends AbstractPrerequisite
{ {
if (version_compare(PHP_VERSION, '5.5.0', '<')) { if (version_compare(PHP_VERSION, '5.5.0', '<')) {
$this->errors[] = [ $this->errors[] = [
'message' => '<strong>PHP 5.5+</strong> is required.', 'message' => 'PHP 5.5+ is required.',
'detail' => 'You are running version '.PHP_VERSION.'. Talk to your hosting provider about upgrading to the latest PHP version.' 'detail' => 'You are running version '.PHP_VERSION.'. Talk to your hosting provider about upgrading to the latest PHP version.'
]; ];
} }

View File

@ -24,8 +24,8 @@ class WritablePaths extends AbstractPrerequisite
foreach ($paths as $path) { foreach ($paths as $path) {
if (! is_writable($path)) { if (! is_writable($path)) {
$this->errors[] = [ $this->errors[] = [
'message' => 'The <strong>'.realpath($path).'</strong> directory is not writable.', 'message' => 'The '.realpath($path).' directory is not writable.',
'detail' => 'Please chmod this directory '.($path !== public_path() ? ' and its contents' : '').' to 0775.' 'detail' => 'Please chmod this directory'.($path !== public_path() ? ' and its contents' : '').' to 0775.'
]; ];
} }
} }