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) {
$column->setPlatformOption('collation', 'utf8_bin');
} elseif ($db === self::SQLITE) {
$column->setPlatformOption('collation', 'BINARY');
$column->setPlatformOption('collate', 'BINARY');
}
}

View File

@ -95,31 +95,20 @@ class InstallCommand extends Command
// Generate database
$output->writeln('Initializing database...');
$process = $this->processHelper->run($output, 'php vendor/bin/doctrine.php orm:schema-tool:create');
if ($process->isSuccessful()) {
$output->writeln(' <info>Success!</info>');
} else {
if ($output->isVerbose()) {
return;
}
$output->writeln(
' <error>Error generating database.</error> Run this command with -vvv to see specific error info.'
);
if (! $this->runCommand('php vendor/bin/doctrine.php orm:schema-tool:create', 'Error generating database.')) {
return;
}
// Run database migrations
$output->writeln('Updating database...');
if (! $this->runCommand('php vendor/bin/doctrine-migrations migrations:migrate', 'Error updating database.')) {
return;
}
// Generate proxies
$output->writeln('Generating proxies...');
$process = $this->processHelper->run($output, 'php vendor/bin/doctrine.php orm:generate-proxies');
if ($process->isSuccessful()) {
$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.'
);
if (! $this->runCommand('php vendor/bin/doctrine.php orm:generate-proxies', 'Error generating proxies.')) {
return;
}
}
@ -283,4 +272,26 @@ class InstallCommand extends Command
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 -->
<file>bin</file>
<file>module</file>
<file>data/migrations</file>
<file>config</file>
<file>public/index.php</file>
<exclude-pattern>config/params/*</exclude-pattern>