diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-04-29 03:48:16 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-04-29 03:48:16 +0000 |
commit | 31f13b569455f82e945349beab204c45d52c9484 (patch) | |
tree | bf00e9b1541d8e2d3ec29f4fc96757e2fd1fdaa8 /includes | |
parent | 483d476a1c22b419ff72bd08cebae191f7dc0e5c (diff) | |
download | brdo-31f13b569455f82e945349beab204c45d52c9484.tar.gz brdo-31f13b569455f82e945349beab204c45d52c9484.tar.bz2 |
#299308 follow-up by David_Rothstein: Fixed Installing Drupal by visiting index.php (rather than install.php) leads to a fatal error when PDO is not enabled.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 9 | ||||
-rw-r--r-- | includes/database/database.inc | 79 | ||||
-rw-r--r-- | includes/database/pgsql/database.inc | 1 |
3 files changed, 36 insertions, 53 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index f05172bbe..2ab460c8c 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -1958,6 +1958,15 @@ function _drupal_bootstrap_database() { header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); exit; } + + // Redirect the user to the installation script if Drupal has not been + // installed yet (i.e., if no $databases array has been defined in the + // settings.php file) and we are not already installing. + if (empty($GLOBALS['databases']) && !drupal_installation_attempted()) { + include_once DRUPAL_ROOT . '/includes/install.inc'; + install_goto('install.php'); + } + // Initialize the database system. Note that the connection // won't be initialized until it is actually requested. require_once DRUPAL_ROOT . '/includes/database/database.inc'; diff --git a/includes/database/database.inc b/includes/database/database.inc index 843117f69..dcf9d6229 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -559,7 +559,6 @@ abstract class DatabaseConnection extends PDO { } } catch (PDOException $e) { - _db_check_install_needed(); if ($options['throw_exception']) { // Add additional debug information. if ($query instanceof DatabaseStatementInterface) { @@ -1408,8 +1407,6 @@ abstract class Database { final public static function parseConnectionInfo() { global $databases; - _db_check_install_needed(); - $database_info = is_array($databases) ? $databases : array(); foreach ($database_info as $index => $info) { foreach ($database_info[$index] as $target => $value) { @@ -1496,46 +1493,38 @@ abstract class Database { if (empty(self::$databaseInfo)) { self::parseConnectionInfo(); } - try { - // If the requested database does not exist then it is an unrecoverable - // error. - if (!isset(self::$databaseInfo[$key])) { - throw new DatabaseConnectionNotDefinedException('The specified database connection is not defined: ' . $key); - } - if (!$driver = self::$databaseInfo[$key][$target]['driver']) { - throw new DatabaseDriverNotSpecifiedException('Driver not specified for this database connection: ' . $key); - } + // If the requested database does not exist then it is an unrecoverable + // error. + if (!isset(self::$databaseInfo[$key])) { + throw new DatabaseConnectionNotDefinedException('The specified database connection is not defined: ' . $key); + } - // We cannot rely on the registry yet, because the registry requires an - // open database connection. - $driver_class = 'DatabaseConnection_' . $driver; - require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/database.inc'; - $new_connection = new $driver_class(self::$databaseInfo[$key][$target]); - $new_connection->setTarget($target); - - // If we have any active logging objects for this connection key, we need - // to associate them with the connection we just opened. - if (!empty(self::$logs[$key])) { - $new_connection->setLogger(self::$logs[$key]); - } + if (!$driver = self::$databaseInfo[$key][$target]['driver']) { + throw new DatabaseDriverNotSpecifiedException('Driver not specified for this database connection: ' . $key); + } - // We need to pass around the simpletest database prefix in the request - // and we put that in the user_agent header. The header HMAC was already - // validated in bootstrap.inc. - if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);/", $_SERVER['HTTP_USER_AGENT'], $matches)) { - $db_prefix_string = is_array($db_prefix) ? $db_prefix['default'] : $db_prefix; - $db_prefix = $db_prefix_string . $matches[1]; - } - return $new_connection; + // We cannot rely on the registry yet, because the registry requires an + // open database connection. + $driver_class = 'DatabaseConnection_' . $driver; + require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/database.inc'; + $new_connection = new $driver_class(self::$databaseInfo[$key][$target]); + $new_connection->setTarget($target); + + // If we have any active logging objects for this connection key, we need + // to associate them with the connection we just opened. + if (!empty(self::$logs[$key])) { + $new_connection->setLogger(self::$logs[$key]); } - catch (Exception $e) { - // It is extremely rare that an exception will be generated here other - // than when installing. We therefore intercept it and try the installer, - // passing on the exception otherwise. - _db_check_install_needed(); - throw $e; + + // We need to pass around the simpletest database prefix in the request + // and we put that in the user_agent header. The header HMAC was already + // validated in bootstrap.inc. + if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\d+);/", $_SERVER['HTTP_USER_AGENT'], $matches)) { + $db_prefix_string = is_array($db_prefix) ? $db_prefix['default'] : $db_prefix; + $db_prefix = $db_prefix_string . $matches[1]; } + return $new_connection; } /** @@ -2900,17 +2889,3 @@ function db_ignore_slave() { } } -/** - * Redirects the user to the installation script. - * - * This will check if Drupal has not been installed yet (i.e., if no $databases - * array has been defined in the settings.php file) and we are not already - * installing. If both are true, the user is redirected to install.php. - */ -function _db_check_install_needed() { - global $databases; - if (empty($databases) && !drupal_installation_attempted()) { - include_once DRUPAL_ROOT . '/includes/install.inc'; - install_goto('install.php'); - } -} diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc index f3ed30b57..35179e855 100644 --- a/includes/database/pgsql/database.inc +++ b/includes/database/pgsql/database.inc @@ -90,7 +90,6 @@ class DatabaseConnection_pgsql extends DatabaseConnection { } } catch (PDOException $e) { - _db_check_install_needed(); if ($options['throw_exception']) { // Add additional debug information. if ($query instanceof DatabaseStatementInterface) { |