aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-09-03 13:34:13 +0200
committerGitHub <noreply@github.com>2016-09-03 13:34:13 +0200
commit2b9c5097d438c5493e5c47c7084fc01d1eb19686 (patch)
treecf83462799bcdf542b4debc0ff51736c43711ad3
parent985f5f9d05f7ff7e443442b1775923b379c141d6 (diff)
parent5070644a12ad264444a812b783a04386d6581cb0 (diff)
downloadwallabag-2b9c5097d438c5493e5c47c7084fc01d1eb19686.tar.gz
wallabag-2b9c5097d438c5493e5c47c7084fc01d1eb19686.tar.zst
wallabag-2b9c5097d438c5493e5c47c7084fc01d1eb19686.zip
Merge pull request #2262 from wallabag/install-check-db-connection
Add a check for the database connection
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php24
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php6
2 files changed, 27 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 813ac720..035eb865 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -72,8 +72,10 @@ class InstallCommand extends ContainerAwareCommand
72 { 72 {
73 $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>'); 73 $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>');
74 74
75 $fulfilled = true; 75 $rows = [];
76 76
77 // testing if database driver exists
78 $fulfilled = true;
77 $label = '<comment>PDO Driver</comment>'; 79 $label = '<comment>PDO Driver</comment>';
78 $status = '<info>OK!</info>'; 80 $status = '<info>OK!</info>';
79 $help = ''; 81 $help = '';
@@ -84,7 +86,23 @@ class InstallCommand extends ContainerAwareCommand
84 $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.'; 86 $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.';
85 } 87 }
86 88
87 $rows = []; 89 $rows[] = [$label, $status, $help];
90
91 // testing if connection to the database can be etablished
92 $label = '<comment>Database connection</comment>';
93 $status = '<info>OK!</info>';
94 $help = '';
95
96 try {
97 $this->getContainer()->get('doctrine')->getManager()->getConnection()->connect();
98 } catch (\Exception $e) {
99 if (false === strpos($e->getMessage(), 'Unknown database')) {
100 $fulfilled = false;
101 $status = '<error>ERROR!</error>';
102 $help = 'Can\'t connect to the database: '.$e->getMessage();
103 }
104 }
105
88 $rows[] = [$label, $status, $help]; 106 $rows[] = [$label, $status, $help];
89 107
90 foreach ($this->functionExists as $functionRequired) { 108 foreach ($this->functionExists as $functionRequired) {
@@ -456,7 +474,7 @@ class InstallCommand extends ContainerAwareCommand
456 } 474 }
457 475
458 // custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite 476 // custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite
459 if ('sqlite' == $schemaManager->getDatabasePlatform()->getName()) { 477 if ('sqlite' === $schemaManager->getDatabasePlatform()->getName()) {
460 $params = $this->getContainer()->get('doctrine.dbal.default_connection')->getParams(); 478 $params = $this->getContainer()->get('doctrine.dbal.default_connection')->getParams();
461 479
462 if (isset($params['path']) && file_exists($params['path'])) { 480 if (isset($params['path']) && file_exists($params['path'])) {
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index 089a1c5f..83f5bf24 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -127,6 +127,12 @@ class InstallCommandTest extends WallabagCoreTestCase
127 127
128 public function testRunInstallCommandWithDatabaseRemoved() 128 public function testRunInstallCommandWithDatabaseRemoved()
129 { 129 {
130 // skipped SQLite check when database is removed because while testing for the connection,
131 // the driver will create the file (so the database) before testing if database exist
132 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
133 $this->markTestSkipped('SQLite spotted: can\'t test with database removed.');
134 }
135
130 $application = new Application($this->getClient()->getKernel()); 136 $application = new Application($this->getClient()->getKernel());
131 $application->add(new DropDatabaseDoctrineCommand()); 137 $application->add(new DropDatabaseDoctrineCommand());
132 138