Improved InstallCommand, adding migrations and removing code duplication

This commit is contained in:
Alejandro Celaya 2016-08-19 15:15:53 +02:00
parent 7d49c1760c
commit ea083e30b6
3 changed files with 33 additions and 21 deletions

View File

@ -25,7 +25,7 @@ class Version20160819142757 extends AbstractMigration
if ($db === self::MYSQL) { if ($db === self::MYSQL) {
$column->setPlatformOption('collation', 'utf8_bin'); $column->setPlatformOption('collation', 'utf8_bin');
} elseif ($db === self::SQLITE) { } elseif ($db === self::SQLITE) {
$column->setPlatformOption('collation', 'BINARY'); $column->setPlatformOption('collate', 'BINARY');
} }
} }

View File

@ -95,31 +95,20 @@ class InstallCommand extends Command
// Generate database // Generate database
$output->writeln('Initializing database...'); $output->writeln('Initializing database...');
$process = $this->processHelper->run($output, 'php vendor/bin/doctrine.php orm:schema-tool:create'); if (! $this->runCommand('php vendor/bin/doctrine.php orm:schema-tool:create', 'Error generating database.')) {
if ($process->isSuccessful()) { return;
$output->writeln(' <info>Success!</info>'); }
} else {
if ($output->isVerbose()) { // Run database migrations
return; $output->writeln('Updating database...');
} if (! $this->runCommand('php vendor/bin/doctrine-migrations migrations:migrate', 'Error updating database.')) {
$output->writeln(
' <error>Error generating database.</error> Run this command with -vvv to see specific error info.'
);
return; return;
} }
// Generate proxies // Generate proxies
$output->writeln('Generating proxies...'); $output->writeln('Generating proxies...');
$process = $this->processHelper->run($output, 'php vendor/bin/doctrine.php orm:generate-proxies'); if (! $this->runCommand('php vendor/bin/doctrine.php orm:generate-proxies', 'Error generating proxies.')) {
if ($process->isSuccessful()) { return;
$output->writeln(' <info>Success!</info>');
} else {
if ($output->isVerbose()) {
return;
}
$output->writeln(
' <error>Error generating proxies.</error> Run this command with -vvv to see specific error info.'
);
} }
} }
@ -283,4 +272,26 @@ class InstallCommand extends Command
return $config; return $config;
} }
/**
* @param string $command
* @param string $errorMessage
* @return bool
*/
protected function runCommand($command, $errorMessage)
{
$process = $this->processHelper->run($this->output, $command);
if ($process->isSuccessful()) {
$this->output->writeln(' <info>Success!</info>');
return true;
} else {
if ($this->output->isVerbose()) {
return false;
}
$this->output->writeln(
' <error>' . $errorMessage . '</error> Run this command with -vvv to see specific error info.'
);
return false;
}
}
} }

View File

@ -18,6 +18,7 @@
<!-- Paths to check --> <!-- Paths to check -->
<file>bin</file> <file>bin</file>
<file>module</file> <file>module</file>
<file>data/migrations</file>
<file>config</file> <file>config</file>
<file>public/index.php</file> <file>public/index.php</file>
<exclude-pattern>config/params/*</exclude-pattern> <exclude-pattern>config/params/*</exclude-pattern>