diff --git a/core/lib/Drupal/Core/Database/DatabaseNotFoundException.php b/core/lib/Drupal/Core/Database/DatabaseNotFoundException.php index 65d1104..b66e60f 100644 --- a/core/lib/Drupal/Core/Database/DatabaseNotFoundException.php +++ b/core/lib/Drupal/Core/Database/DatabaseNotFoundException.php @@ -9,4 +9,4 @@ /** * Exception thrown if specified database is not found. */ -class DatabaseNotFoundException extends \RuntimeException {} +class DatabaseNotFoundException extends \RuntimeException implements DatabaseException {} diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php index 57a05c8..91652de 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php @@ -175,7 +175,7 @@ public function databaseType() { */ public function createDatabase($database) { if ($database != Database::getConnection()->escapeDatabase($database)) { - throw new DatabaseInvalidNameException(); + throw new DatabaseInvalidNameException("$database is an invalid name."); } try { diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php index f2bdab3..ecfe55d 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php @@ -10,7 +10,7 @@ use Drupal\Core\Database\Install\Tasks as InstallTasks; use Drupal\Core\Database\Database; use Drupal\Core\Database\Driver\mysql\Connection; -use Drupal\Core\Database\DatabaseNotFoundException; +use Drupal\Core\Database\DatabaseException; /** * Specifies installation tasks for MySQL and equivalent databases. @@ -83,19 +83,8 @@ protected function connect() { // create the database. Database::getConnection()->createDatabase($database); } - catch (\Exception $e) { - switch (get_class($e)) { - case 'Drupal\Core\Database\DatabaseInvalidNameException': - $this->fail(t('The database name contains illegal characters')); - break; - - case 'Drupal\Core\Database\DatabaseNotFoundException': - $this->fail(t('Database %database not found. The server reports the following message when attempting to create the database: %error.', array('%database' => $database, '%error' => $e->getMessage()))); - break; - - default: - $this->fail(t('An unspecified database error occurred')); - } + catch (DatabaseException $e) { + $this->fail(t('The server reports the following message when attempting to create database %database: %error.', array('%database' => $database, '%error' => $e->getMessage()))); } } else { diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index 5769a60..baa265a 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -251,7 +251,7 @@ public function databaseType() { */ public function createDatabase($database) { if ($database != Database::getConnection()->escapeDatabase($database)) { - throw new DatabaseInvalidNameException(); + throw new DatabaseInvalidNameException("$database is an invalid name."); } // If the PECL intl extension is installed, use it to determine the proper diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php index 9739520..c9dfa7a 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php @@ -10,7 +10,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\Install\Tasks as InstallTasks; use Drupal\Core\Database\Driver\pgsql\Connection; -use Drupal\Core\Database\DatabaseNotFoundException; +use Drupal\Core\Database\DatabaseException; /** * Specifies installation tasks for PostgreSQL databases. @@ -93,19 +93,8 @@ protected function connect() { Database::getConnection(); $this->pass('Drupal can CONNECT to the database ok.'); } - catch (\Exception $e) { - switch (get_class($e)) { - case 'Drupal\Core\Database\DatabaseInvalidNameException': - $this->fail(t('The database name contains illegal characters')); - break; - - case 'Drupal\Core\Database\DatabaseNotFoundException': - $this->fail(t('Database %database not found. The server reports the following message when attempting to create the database: %error.', array('%database' => $database, '%error' => $e->getMessage()))); - break; - - default: - $this->fail(t('An unspecified database error occurred')); - } + catch (DatabaseException $e) { + $this->fail(t('The server reports the following message when attempting to create database %database: %error.', array('%database' => $database, '%error' => $e->getMessage()))); } } else {