diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-11-22 13:51:38 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-11-22 13:51:38 +0000 |
commit | 33cf35a6e8a7cab73147af368f2ee4d16a41dbd0 (patch) | |
tree | 2c0d423e51ff3c4a57531afde5e8bf173541d9e0 /includes | |
parent | 6608f70cff82808b3c9bbc98ae3dd76d123330f0 (diff) | |
download | brdo-33cf35a6e8a7cab73147af368f2ee4d16a41dbd0.tar.gz brdo-33cf35a6e8a7cab73147af368f2ee4d16a41dbd0.tar.bz2 |
- Patch #335614 by Damien Tournoud: getActiveConnection() and getConnection() were broken when was not found. Now with tests\!
Diffstat (limited to 'includes')
-rw-r--r-- | includes/database/database.inc | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc index e9b2ff0b6..fc94e55e7 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -891,14 +891,17 @@ abstract class Database { final public static function getActiveConnection($target = 'default') { // This could just be a call to getConnection(), but that's an extra // method call for every single query. - if (!empty(self::$ignoreTargets[self::$activeKey][$target])) { + + // If the requested target does not exist, or if it is ignored, we fall back + // to the default target. The target is typically either "default" or "slave", + // indicating to use a slave SQL server if one is available. If it's not + // available, then the default/master server is the correct server to use. + if (!empty(self::$ignoreTargets[self::$activeKey][$target]) || !isset(self::$databaseInfo[self::$activeKey][$target])) { $target = 'default'; } if (!isset(self::$connections[self::$activeKey][$target])) { - // If we're trying to open a target that doesn't exist, we need to know - // what the actual target we got was. - $target = self::openConnection(self::$activeKey, $target); + self::openConnection(self::$activeKey, $target); } return isset(self::$connections[self::$activeKey][$target]) ? self::$connections[self::$activeKey][$target] : NULL; @@ -911,14 +914,16 @@ abstract class Database { * The corresponding connection object. */ final public static function getConnection($key = 'default', $target = 'default') { - if (!empty(self::$ignoreTargets[$key][$target])) { + // If the requested target does not exist, or if it is ignored, we fall back + // to the default target. The target is typically either "default" or "slave", + // indicating to use a slave SQL server if one is available. If it's not + // available, then the default/master server is the correct server to use. + if (!empty(self::$ignoreTargets[$key][$target]) || !isset(self::$databaseInfo[$key][$target])) { $target = 'default'; } if (!isset(self::$connections[$key][$target])) { - // If we're trying to open a target that doesn't exist, we need to know - // what the actual target we got was. - $target = self::openConnection(self::$activeKey, $target); + self::openConnection($key, $target); } return isset(self::$connections[$key][$target]) ? self::$connections[$key][$target] : NULL; @@ -1028,10 +1033,7 @@ abstract class Database { * The database connection key, as specified in settings.php. The default * is "default". * @param $target - * The database target to open. If the specified target does not exist, - * the "default" target will be used instead. - * @return - * The name of the target that was actually opened. + * The database target to open. */ final protected static function openConnection($key, $target) { global $db_prefix; @@ -1041,16 +1043,9 @@ abstract class Database { } try { // If the requested database does not exist then it is an unrecoverable error. - // If the requested target does not exist, however, we fall back to the default - // target. The target is typically either "default" or "slave", indicating to - // use a slave SQL server if one is available. If it's not available, then the - // default/master server is the correct server to use. if (!isset(self::$databaseInfo[$key])) { throw new Exception('DB does not exist'); } - if (!isset(self::$databaseInfo[$key][$target])) { - $target = 'default'; - } if (!$driver = self::$databaseInfo[$key][$target]['driver']) { throw new Exception('Drupal is not set up'); @@ -1074,10 +1069,6 @@ abstract class Database { if (preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT'])) { $db_prefix .= $_SERVER['HTTP_USER_AGENT']; } - - // Return the target that was actually opened in case the requested one - // didn't exist. - return $target; } catch (Exception $e) { // It is extremely rare that an exception will be generated here other |