]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add a check for the database connection
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 3 Sep 2016 07:24:34 +0000 (09:24 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 3 Sep 2016 07:24:34 +0000 (09:24 +0200)
Checking for the driver isn't enough.
We are now checking if we can etablish a connection to the database before trying to do anything.
By displaying the error from the Exception (in case of error) we hope to reduce issues overload about people getting error with the database

src/Wallabag/CoreBundle/Command/InstallCommand.php

index 813ac720de0c9d53c4a42c35d7bc49a76f2d2d48..50d0dfff49b56adefe139d929d90fb709712f8f2 100644 (file)
@@ -72,8 +72,10 @@ class InstallCommand extends ContainerAwareCommand
     {
         $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>');
 
-        $fulfilled = true;
+        $rows = [];
 
+        // testing if database driver exists
+        $fulfilled = true;
         $label = '<comment>PDO Driver</comment>';
         $status = '<info>OK!</info>';
         $help = '';
@@ -84,7 +86,21 @@ class InstallCommand extends ContainerAwareCommand
             $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.';
         }
 
-        $rows = [];
+        $rows[] = [$label, $status, $help];
+
+        // testing if connection to the database can be etablished
+        $label = '<comment>Database connection</comment>';
+        $status = '<info>OK!</info>';
+        $help = '';
+
+        try {
+            $this->getContainer()->get('doctrine')->getManager()->getConnection()->connect();
+        } catch (\Exception $e) {
+            $fulfilled = false;
+            $status = '<error>ERROR!</error>';
+            $help = 'Can\'t connect to the database: '.$e->getMessage();
+        }
+
         $rows[] = [$label, $status, $help];
 
         foreach ($this->functionExists as $functionRequired) {