Commit a3c3f982 authored by anarcat's avatar anarcat
Browse files

1102650 by helmo - fail more gracefully in db connexions

parent a08de3bc
...@@ -21,6 +21,8 @@ function db_drush_exit() { ...@@ -21,6 +21,8 @@ function db_drush_exit() {
function db_drush_help($section) { function db_drush_help($section) {
switch ($section) { switch ($section) {
case 'error:PROVISION_CONNECT_DB_FAILED' :
return dt('Unable to connect to database server.');
case 'error:PROVISION_CREATE_DB_FAILED' : case 'error:PROVISION_CREATE_DB_FAILED' :
return dt('Unable to create new databases.'); return dt('Unable to create new databases.');
case 'error:PROVISION_DROP_DB_FAILED' : case 'error:PROVISION_DROP_DB_FAILED' :
...@@ -56,12 +58,15 @@ class provisionService_db extends provisionService { ...@@ -56,12 +58,15 @@ class provisionService_db extends provisionService {
} }
function verify_server_cmd() { function verify_server_cmd() {
$this->connect(); if ($this->connect()) {
if ($this->can_create_database()) { if ($this->can_create_database()) {
drush_log(dt('Provision can create new databases.'), 'message'); drush_log(dt('Provision can create new databases.'), 'message');
} }
else { else {
drush_set_error('PROVISION_CREATE_DB_FAILED'); drush_set_error('PROVISION_CREATE_DB_FAILED');
}
} else {
drush_set_error('PROVISION_CONNECT_DB_FAILED');
} }
} }
...@@ -281,6 +286,7 @@ class provisionService_db_pdo extends provisionService_db { ...@@ -281,6 +286,7 @@ class provisionService_db_pdo extends provisionService_db {
function connect() { function connect() {
try { try {
$this->conn = new PDO($this->dsn, $this->creds['user'], $this->creds['pass']); $this->conn = new PDO($this->dsn, $this->creds['user'], $this->creds['pass']);
return $this->conn;
} }
catch (PDOException $e) { catch (PDOException $e) {
return drush_set_error('PROVISION_DB_CONNECT_FAIL', $e->getMessage()); return drush_set_error('PROVISION_DB_CONNECT_FAIL', $e->getMessage());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment