Tim Starling has submitted this change and it was merged. Change subject: (Bug 42461) Remove call to "new Database()" ......................................................................
(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 --- M includes/db/DatabaseError.php M includes/db/LoadBalancer.php 2 files changed, 12 insertions(+), 11 deletions(-) Approvals: Tim Starling: Verified; Looks good to me, approved jenkins-bot: Checked diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 331b8ae..628a2af 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -37,7 +37,7 @@ * @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 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 @@ # 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 @@ * @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 aeebb13..1e85927 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -481,7 +481,7 @@ 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 @@ $conn = $this->openConnection( $i, $wiki ); if ( !$conn ) { wfProfileOut( __METHOD__ ); - return $this->reportConnectionError( $this->mErrorConnection ); + return $this->reportConnectionError(); } wfProfileOut( __METHOD__ ); @@ -708,17 +708,18 @@ } /** - * @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" ); -- To view, visit https://gerrit.wikimedia.org/r/45941 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If9570b45ea7285de2b8b2391e704bc01f76be48a Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Platonides <platoni...@gmail.com> Gerrit-Reviewer: Platonides <platoni...@gmail.com> Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits