* @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 );
}
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 ) != '' ) {
# No database access
MessageCache::singleton()->disable();
- if ( trim( $this->error ) == '' ) {
+ if ( trim( $this->error ) == '' && $this->db ) {
$this->error = $this->db->getProperty( 'mServer' );
}
* @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" .
if ( $i === false ) {
$this->mLastError = 'No working slave server: ' . $this->mLastError;
wfProfileOut( __METHOD__ );
- return $this->reportConnectionError( $this->mErrorConnection );
+ return $this->reportConnectionError();
}
}
$conn = $this->openConnection( $i, $wiki );
if ( !$conn ) {
wfProfileOut( __METHOD__ );
- return $this->reportConnectionError( $this->mErrorConnection );
+ return $this->reportConnectionError();
}
wfProfileOut( __METHOD__ );
}
/**
- * @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" );