Răsfoiți Sursa

Added symfony process to run initialization commands

Alejandro Celaya 7 ani în urmă
părinte
comite
4bbdccf981
3 a modificat fișierele cu 19 adăugiri și 1 ștergeri
  1. 1 0
      .gitignore
  2. 1 0
      composer.json
  3. 17 1
      module/CLI/src/Command/Install/InstallCommand.php

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@ build
 composer.lock
 vendor/
 .env
+data/database.sqlite

+ 1 - 0
composer.json

@@ -27,6 +27,7 @@
         "doctrine/orm": "^2.5",
         "guzzlehttp/guzzle": "^6.2",
         "symfony/console": "^3.0",
+        "symfony/process": "^3.0",
         "firebase/php-jwt": "^4.0",
         "monolog/monolog": "^1.21",
         "theorchard/monolog-cascade": "^0.4",

+ 17 - 1
module/CLI/src/Command/Install/InstallCommand.php

@@ -4,6 +4,7 @@ namespace Shlinkio\Shlink\CLI\Command\Install;
 use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
 use Shlinkio\Shlink\Core\Service\UrlShortener;
 use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\ProcessHelper;
 use Symfony\Component\Console\Helper\QuestionHelper;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -34,6 +35,10 @@ class InstallCommand extends Command
      * @var QuestionHelper
      */
     private $questionHelper;
+    /**
+     * @var ProcessHelper
+     */
+    private $processHelper;
     /**
      * @var WriterInterface
      */
@@ -56,6 +61,7 @@ class InstallCommand extends Command
         $this->input = $input;
         $this->output = $output;
         $this->questionHelper = $this->getHelper('question');
+        $this->processHelper = $this->getHelper('process');
         $params = [];
 
         $output->writeln([
@@ -85,7 +91,17 @@ class InstallCommand extends Command
         // Generate config params files
         $config = $this->buildAppConfig($params);
         $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
+        $output->write('Initializing database...');
+        $this->processHelper->run($output, 'php vendor/bin/doctrine.php orm:schema-tool:create');
+        $output->writeln(' <info>Success!</info>');
+
+        // Generate proxies
+        $output->write('Generating proxies...');
+        $this->processHelper->run($output, 'php vendor/bin/doctrine.php orm:generate-proxies');
+        $output->writeln(' <info>Success!</info>');
     }
 
     protected function askDatabase()