From: Platonides Date: Sat, 26 Jan 2013 15:38:29 +0000 (+0100) Subject: (Bug 42461) Remove call to "new Database()" X-Git-Tag: 1.31.0-rc.0~20311 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=276319122142a502a275343b9eb2481eaf916b92;p=lhc%2Fweb%2Fwiklou.git (Bug 42461) Remove call to "new Database()" * Refactored LoadBalancer::reportConnectionError() * Removed PHP4-style reference from DatabaseError constructors * Allowed to not pass a database to the DBError family of exceptions. Change-Id: If9570b45ea7285de2b8b2391e704bc01f76be48a --- diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 331b8ae2c8..628a2afca5 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -37,7 +37,7 @@ class DBError extends MWException { * @param $db DatabaseBase object which threw the error * @param string $error A simple error message to be used for debugging */ - function __construct( DatabaseBase &$db, $error ) { + function __construct( DatabaseBase $db = null, $error ) { $this->db = $db; parent::__construct( $error ); } @@ -91,7 +91,7 @@ class DBError extends MWException { class DBConnectionError extends DBError { public $error; - function __construct( DatabaseBase &$db, $error = 'unknown error' ) { + function __construct( DatabaseBase $db = null, $error = 'unknown error' ) { $msg = 'DB connection error'; if ( trim( $error ) != '' ) { @@ -158,7 +158,7 @@ class DBConnectionError extends DBError { # No database access MessageCache::singleton()->disable(); - if ( trim( $this->error ) == '' ) { + if ( trim( $this->error ) == '' && $this->db ) { $this->error = $this->db->getProperty( 'mServer' ); } @@ -288,7 +288,7 @@ class DBQueryError extends DBError { * @param $sql string * @param $fname string */ - function __construct( DatabaseBase &$db, $error, $errno, $sql, $fname ) { + function __construct( DatabaseBase $db, $error, $errno, $sql, $fname ) { $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" . "Query: $sql\n" . "Function: $fname\n" . diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index aeebb13409..1e85927826 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -481,7 +481,7 @@ class LoadBalancer { if ( $i === false ) { $this->mLastError = 'No working slave server: ' . $this->mLastError; wfProfileOut( __METHOD__ ); - return $this->reportConnectionError( $this->mErrorConnection ); + return $this->reportConnectionError(); } } @@ -489,7 +489,7 @@ class LoadBalancer { $conn = $this->openConnection( $i, $wiki ); if ( !$conn ) { wfProfileOut( __METHOD__ ); - return $this->reportConnectionError( $this->mErrorConnection ); + return $this->reportConnectionError(); } wfProfileOut( __METHOD__ ); @@ -708,17 +708,18 @@ class LoadBalancer { } /** - * @param $conn - * @return bool * @throws DBConnectionError + * @return bool */ - function reportConnectionError( &$conn ) { + private function reportConnectionError() { + $conn = $this->mErrorConnection; // The connection which caused the error + if ( !is_object( $conn ) ) { // No last connection, probably due to all servers being too busy wfLogDBError( "LB failure with no last connection. Connection error: {$this->mLastError}\n" ); - $conn = new Database; + // If all servers were busy, mLastError will contain something sensible - throw new DBConnectionError( $conn, $this->mLastError ); + throw new DBConnectionError( null, $this->mLastError ); } else { $server = $conn->getProperty( 'mServer' ); wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );