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

View File

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

View File

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