From ea083e30b6ec07418b965690b38c0c0b3d5e4620 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya <alejandro@alejandrocelaya.com> Date: Fri, 19 Aug 2016 15:15:53 +0200 Subject: [PATCH] Improved InstallCommand, adding migrations and removing code duplication --- data/migrations/Version20160819142757.php | 2 +- .../src/Command/Install/InstallCommand.php | 51 +++++++++++-------- phpcs.xml | 1 + 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/data/migrations/Version20160819142757.php b/data/migrations/Version20160819142757.php index 75c30018..40200c53 100644 --- a/data/migrations/Version20160819142757.php +++ b/data/migrations/Version20160819142757.php @@ -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'); } } diff --git a/module/CLI/src/Command/Install/InstallCommand.php b/module/CLI/src/Command/Install/InstallCommand.php index 6df92f26..75eac1ef 100644 --- a/module/CLI/src/Command/Install/InstallCommand.php +++ b/module/CLI/src/Command/Install/InstallCommand.php @@ -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; + } + } } diff --git a/phpcs.xml b/phpcs.xml index 5b686079..bd3ef63a 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -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>