* This handles the work of showing exceptions so that MWException does not have too. * Simplify the DBError classes to regular Exception classes. Lots of pointless prettification has been removed, but DBConnectionError still gets the usual special treatment of a fallback page and Google form. * Remove hacky file cache fallback code that probably did not work. * Make MWExceptionHandler::report() wrap MWExceptionExposer::output(). * Make MWException::runHooks() wrap MWExceptionExposer::runHooks(). Change-Id: I5dfdc84e94ddac65417226cf7c84513ebb9f9faa
149 lines
3.6 KiB
PHP
149 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* This file contains database error classes.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
* @ingroup Database
|
|
*/
|
|
|
|
/**
|
|
* Database error base class
|
|
* @ingroup Database
|
|
*/
|
|
class DBError extends Exception {
|
|
/** @var IDatabase */
|
|
public $db;
|
|
|
|
/**
|
|
* Construct a database error
|
|
* @param IDatabase $db Object which threw the error
|
|
* @param string $error A simple error message to be used for debugging
|
|
*/
|
|
function __construct( IDatabase $db = null, $error ) {
|
|
$this->db = $db;
|
|
parent::__construct( $error );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Base class for the more common types of database errors. These are known to occur
|
|
* frequently, so we try to give friendly error messages for them.
|
|
*
|
|
* @ingroup Database
|
|
* @since 1.23
|
|
*/
|
|
class DBExpectedError extends DBError {
|
|
}
|
|
|
|
/**
|
|
* @ingroup Database
|
|
*/
|
|
class DBConnectionError extends DBExpectedError {
|
|
/**
|
|
* @param IDatabase $db Object throwing the error
|
|
* @param string $error Error text
|
|
*/
|
|
function __construct( IDatabase $db = null, $error = 'unknown error' ) {
|
|
$msg = 'Cannot access the database';
|
|
if ( trim( $error ) != '' ) {
|
|
$msg .= ": $error";
|
|
}
|
|
|
|
parent::__construct( $db, $msg );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @ingroup Database
|
|
*/
|
|
class DBQueryError extends DBExpectedError {
|
|
/** @var string */
|
|
public $error;
|
|
/** @var integer */
|
|
public $errno;
|
|
/** @var string */
|
|
public $sql;
|
|
/** @var string */
|
|
public $fname;
|
|
|
|
/**
|
|
* @param IDatabase $db
|
|
* @param string $error
|
|
* @param int|string $errno
|
|
* @param string $sql
|
|
* @param string $fname
|
|
*/
|
|
function __construct( IDatabase $db, $error, $errno, $sql, $fname ) {
|
|
if ( $db instanceof DatabaseBase && $db->wasConnectionError( $errno ) ) {
|
|
$message = "A connection error occured. \n" .
|
|
"Query: $sql\n" .
|
|
"Function: $fname\n" .
|
|
"Error: $errno $error\n";
|
|
} else {
|
|
$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" .
|
|
"Error: $errno $error\n";
|
|
}
|
|
parent::__construct( $db, $message );
|
|
|
|
$this->error = $error;
|
|
$this->errno = $errno;
|
|
$this->sql = $sql;
|
|
$this->fname = $fname;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @ingroup Database
|
|
*/
|
|
class DBReadOnlyError extends DBExpectedError {
|
|
}
|
|
|
|
/**
|
|
* @ingroup Database
|
|
*/
|
|
class DBTransactionError extends DBExpectedError {
|
|
}
|
|
|
|
/**
|
|
* Exception class for replica DB wait timeouts
|
|
* @ingroup Database
|
|
*/
|
|
class DBReplicationWaitError extends DBExpectedError {
|
|
}
|
|
|
|
/**
|
|
* @ingroup Database
|
|
*/
|
|
class DBUnexpectedError extends DBError {
|
|
}
|
|
|
|
/**
|
|
* Exception class for attempted DB access
|
|
* @ingroup Database
|
|
*/
|
|
class DBAccessError extends DBUnexpectedError {
|
|
public function __construct() {
|
|
parent::__construct( "Mediawiki tried to access the database via wfGetDB(). " .
|
|
"This is not allowed, because database access has been disabled." );
|
|
}
|
|
}
|
|
|