]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Command/InstallCommand.php
Wallabag can’t work on PostgreSQL <= 9.1
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Command / InstallCommand.php
index cc7c2c94cf268be86cd4de51d895404a7d433ec2..2daf2dd85ae3cd372c0c130fdd3700a04aaa776e 100644 (file)
@@ -9,7 +9,7 @@ use Symfony\Component\Console\Helper\Table;
 use Symfony\Component\Console\Input\ArrayInput;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Output\NullOutput;
+use Symfony\Component\Console\Output\BufferedOutput;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Question\ConfirmationQuestion;
 use Symfony\Component\Console\Question\Question;
@@ -72,6 +72,7 @@ class InstallCommand extends ContainerAwareCommand
     protected function checkRequirements()
     {
         $this->defaultOutput->writeln('<info><comment>Step 1 of 4.</comment> Checking system requirements.</info>');
+        $doctrineManager = $this->getContainer()->get('doctrine')->getManager();
 
         $rows = [];
 
@@ -95,9 +96,10 @@ class InstallCommand extends ContainerAwareCommand
         $help = '';
 
         try {
-            $this->getContainer()->get('doctrine')->getManager()->getConnection()->connect();
+            $doctrineManager->getConnection()->connect();
         } catch (\Exception $e) {
-            if (false === strpos($e->getMessage(), 'Unknown database')) {
+            if (false === strpos($e->getMessage(), 'Unknown database')
+                && false === strpos($e->getMessage(), 'database "'.$this->getContainer()->getParameter('database_name').'" does not exist')) {
                 $fulfilled = false;
                 $status = '<error>ERROR!</error>';
                 $help = 'Can\'t connect to the database: '.$e->getMessage();
@@ -106,6 +108,26 @@ class InstallCommand extends ContainerAwareCommand
 
         $rows[] = [$label, $status, $help];
 
+        // testing if PostgreSQL > 9.1
+        $label = '<comment>SGBD version</comment>';
+        $status = '<info>OK!</info>';
+        $help = '';
+
+        if ('postgresql' === $doctrineManager->getConnection()->getSchemaManager()->getDatabasePlatform()->getName()) {
+            // return version should be like "PostgreSQL 9.5.4 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.38), 64-bit"
+            $version = $doctrineManager->getConnection()->query('SELECT version();')->fetchColumn();
+
+            preg_match('/PostgreSQL ([0-9\.]+)/i', $version, $matches);
+
+            if (isset($matches[1]) & version_compare($matches[1], '9.2.0', '<')) {
+                $fulfilled = false;
+                $status = '<error>ERROR!</error>';
+                $help = 'PostgreSQL should be greater than 9.1 (actual version: '.$matches[1].')';
+            }
+        }
+
+        $rows[] = [$label, $status, $help];
+
         foreach ($this->functionExists as $functionRequired) {
             $label = '<comment>'.$functionRequired.'</comment>';
             $status = '<info>OK!</info>';
@@ -363,7 +385,7 @@ class InstallCommand extends ContainerAwareCommand
             ],
             [
                 'name' => 'piwik_host',
-                'value' => 'http://v2.wallabag.org',
+                'value' => 'v2.wallabag.org',
                 'section' => 'analytics',
             ],
             [
@@ -420,16 +442,18 @@ class InstallCommand extends ContainerAwareCommand
         }
 
         $this->getApplication()->setAutoExit(false);
-        $exitCode = $this->getApplication()->run(new ArrayInput($parameters), new NullOutput());
+
+        $output = new BufferedOutput();
+        $exitCode = $this->getApplication()->run(new ArrayInput($parameters), $output);
 
         if (0 !== $exitCode) {
             $this->getApplication()->setAutoExit(true);
 
-            $errorMessage = sprintf('The command "%s" terminated with an error code: %u.', $command, $exitCode);
-            $this->defaultOutput->writeln("<error>$errorMessage</error>");
-            $exception = new \Exception($errorMessage, $exitCode);
+            $this->defaultOutput->writeln('');
+            $this->defaultOutput->writeln('<error>The command "'.$command.'" generates some errors: </error>');
+            $this->defaultOutput->writeln($output->fetch());
 
-            throw $exception;
+            die();
         }
 
         // PDO does not always close the connection after Doctrine commands.