Improved check on update and install commands

This commit is contained in:
Alejandro Celaya 2017-07-03 13:17:44 +02:00
parent c3cc88f03e
commit 1fe2e6f6bd
3 changed files with 23 additions and 12 deletions

View File

@ -100,9 +100,15 @@ abstract class AbstractInstallCommand extends Command
$this->configWriter->toFile('config/params/generated_config.php', $config, false);
$output->writeln(['<info>Custom configuration properly generated!</info>', '']);
// Generate database
if (! $this->createDatabase()) {
return;
// If current command is not update, generate database
if (! $this->isUpdate()) {
$this->output->writeln('Initializing database...');
if (! $this->runCommand(
'php vendor/bin/doctrine.php orm:schema-tool:create',
'Error generating database.'
)) {
return;
}
}
// Run database migrations
@ -295,11 +301,6 @@ abstract class AbstractInstallCommand extends Command
return $config;
}
/**
* @return bool
*/
abstract protected function createDatabase();
/**
* @param string $command
* @param string $errorMessage
@ -322,4 +323,9 @@ abstract class AbstractInstallCommand extends Command
);
return false;
}
/**
* @return bool
*/
abstract protected function isUpdate();
}

View File

@ -3,9 +3,11 @@ namespace Shlinkio\Shlink\CLI\Command\Install;
class InstallCommand extends AbstractInstallCommand
{
protected function createDatabase()
/**
* @return bool
*/
protected function isUpdate()
{
$this->output->writeln('Initializing database...');
return $this->runCommand('php vendor/bin/doctrine.php orm:schema-tool:create', 'Error generating database.');
return false;
}
}

View File

@ -3,7 +3,10 @@ namespace Shlinkio\Shlink\CLI\Command\Install;
class UpdateCommand extends AbstractInstallCommand
{
public function createDatabase()
/**
* @return bool
*/
protected function isUpdate()
{
return true;
}