From: Sam Reed Date: Wed, 18 Aug 2010 14:15:32 +0000 (+0000) Subject: Revert r71250 r71251 r71252 r71253 X-Git-Tag: 1.31.0-rc.0~35450 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=85af1b0901e5f37919caeb48de5df01c19ac0a18;p=lhc%2Fweb%2Fwiklou.git Revert r71250 r71251 r71252 r71253 Know what the problem is, roughly, can't fix atm, so not leaving phase3 broken --- diff --git a/config/Installer.php b/config/Installer.php index 2270be1302..e2a29d1361 100644 --- a/config/Installer.php +++ b/config/Installer.php @@ -929,6 +929,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { $conf->RootUser, $conf->RootPW, false, + false, 1 ); if ( !$wgDatabase->isOpen() ) { @@ -1048,7 +1049,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { $wgDBadminuser = $conf->RootUser; $wgDBadminpassword = $conf->RootPW; echo "
  • Attempting to create DB user.
  • "; - $wgDatabase = $dbc->newFromParams('DUMMY', $wgDBadminuser, $wgDBadminpassword, $wgDBname, 64); + $wgDatabase = $dbc->newFromParams('DUMMY', $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1, 64); if ($wgDatabase->isOpen()) { $wgDBOracleDefTS = $conf->DBdefTS_ora; $wgDBOracleTempTS = $conf->DBtempTS_ora; diff --git a/includes/db/Database.php b/includes/db/Database.php index b9ce24f070..ce676e808e 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -32,6 +32,7 @@ abstract class DatabaseBase { protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname; protected $mOpened = false; + protected $mFailFunction; protected $mTablePrefix; protected $mFlags; protected $mTrxLevel = 0; @@ -45,6 +46,14 @@ abstract class DatabaseBase { #------------------------------------------------------------------------------ # These optionally set a variable and return the previous state + /** + * Fail function, takes a Database as a parameter + * Set to false for default, 1 for ignore errors + */ + function failFunction( $function = null ) { + return wfSetVar( $this->mFailFunction, $function ); + } + /** * Boolean, controls output of large amounts of debug information */ @@ -282,11 +291,12 @@ abstract class DatabaseBase { * @param $user String: database user name * @param $password String: database user password * @param $dbName String: database name + * @param $failFunction * @param $flags * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php */ function __construct( $server = false, $user = false, $password = false, $dbName = false, - $flags = 0, $tablePrefix = 'get from global' ) { + $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) { global $wgOut, $wgDBprefix, $wgCommandLineMode; # Can't get a reference if it hasn't been set yet @@ -294,6 +304,7 @@ abstract class DatabaseBase { $wgOut = null; } + $this->mFailFunction = $failFunction; $this->mFlags = $flags; if ( $this->mFlags & DBO_DEFAULT ) { @@ -329,16 +340,18 @@ abstract class DatabaseBase { * @param $user String: database user name * @param $password String: database user password * @param $dbName String: database name + * @param failFunction * @param $flags */ - static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) { wfDeprecated( __METHOD__ ); - return new DatabaseMysql( $server, $user, $password, $dbName, $flags ); + return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags ); } /** * Usually aborts on failure + * If the failFunction is set to a non-zero integer, returns success * @param $server String: database server host * @param $user String: database user name * @param $password String: database user password @@ -390,7 +403,16 @@ abstract class DatabaseBase { $error = $myError; } - throw new DBConnectionError( $this, $error ); + if ( $this->mFailFunction ) { + # Legacy error handling method + if ( !is_int( $this->mFailFunction ) ) { + $ff = $this->mFailFunction; + $ff( $this, $error ); + } + } else { + # New method + throw new DBConnectionError( $this, $error ); + } } /** diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index 646f6650e1..c91dc86833 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -112,6 +112,7 @@ class DatabaseIbm_db2 extends DatabaseBase { protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname; protected $mOut, $mOpened = false; + protected $mFailFunction; protected $mTablePrefix; protected $mFlags; protected $mTrxLevel = 0; @@ -163,6 +164,7 @@ class DatabaseIbm_db2 extends DatabaseBase { * These can be safely inherited * * Getter/Setter: (18) + * failFunction * bufferResults * ignoreErrors * trxLevel @@ -403,19 +405,22 @@ class DatabaseIbm_db2 extends DatabaseBase { * @param $user String: username * @param $password String: password * @param $dbName String: database name on the server + * @param $failFunction Callback (optional) * @param $flags Integer: database behaviour flags (optional, unused) * @param $schema String */ public function DatabaseIbm_db2($server = false, $user = false, $password = false, - $dbName = false, $flags = 0, + $dbName = false, $failFunction = false, $flags = 0, $schema = self::USE_GLOBAL ) { + global $wgOut, $wgDBmwschema; # Can't get a reference if it hasn't been set yet if ( !isset( $wgOut ) ) { $wgOut = null; } $this->mOut =& $wgOut; + $this->mFailFunction = $failFunction; $this->mFlags = DBO_TRX | $flags; if ( $schema == self::USE_GLOBAL ) { @@ -574,11 +579,13 @@ class DatabaseIbm_db2 extends DatabaseBase { * @param $user String: username * @param $password String * @param $dbName String: database name on the server + * @param $failFunction Callback (optional) * @param $flags Integer: database behaviour flags (optional, unused) * @return DatabaseIbm_db2 object */ - static function newFromParams( $server, $user, $password, $dbName, $flags = 0) { - return new DatabaseIbm_db2( $server, $user, $password, $dbName, $flags ); + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0) + { + return new DatabaseIbm_db2( $server, $user, $password, $dbName, $failFunction, $flags ); } /** diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index efe755c52b..0c8125f79e 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -18,10 +18,12 @@ class DatabaseMssql extends DatabaseBase { var $mAffectedRows = NULL; function __construct( $server = false, $user = false, $password = false, $dbName = false, - $flags = 0 ) + $failFunction = false, $flags = 0 ) { + $this->mFailFunction = $failFunction; $this->mFlags = $flags; $this->open( $server, $user, $password, $dbName ); + } function cascadingDeletes() { @@ -49,12 +51,14 @@ class DatabaseMssql extends DatabaseBase { return false; } - static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) { - return new DatabaseMssql( $server, $user, $password, $dbName, $flags ); + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) + { + return new DatabaseMssql( $server, $user, $password, $dbName, $failFunction, $flags ); } /** * Usually aborts on failure + * If the failFunction is set to a non-zero integer, returns success */ function open( $server, $user, $password, $dbName ) { # Test for driver support, to avoid suppressed fatal error diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 9296c55827..eae997c9ef 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -185,10 +185,10 @@ class DatabaseOracle extends DatabaseBase { var $mFieldInfoCache = array(); function __construct( $server = false, $user = false, $password = false, $dbName = false, - $flags = 0, $tablePrefix = 'get from global' ) + $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) { $tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper( $tablePrefix ); - parent::__construct( $server, $user, $password, $dbName, $flags, $tablePrefix ); + parent::__construct( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix ); wfRunHooks( 'DatabaseOraclePostInit', array( &$this ) ); } @@ -218,12 +218,14 @@ class DatabaseOracle extends DatabaseBase { return true; } - static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ){ - return new DatabaseOracle( $server, $user, $password, $dbName, $flags ); + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) + { + return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags ); } /** * Usually aborts on failure + * If the failFunction is set to a non-zero integer, returns success */ function open( $server, $user, $password, $dbName ) { if ( !function_exists( 'oci_connect' ) ) { diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 5cb1a33d8d..b956a6b79f 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -97,10 +97,13 @@ class DatabasePostgres extends DatabaseBase { var $mAffectedRows = null; function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false, - $flags = 0 ) + $failFunction = false, $flags = 0 ) { + + $this->mFailFunction = $failFunction; $this->mFlags = $flags; $this->open( $server, $user, $password, $dbName); + } function getType() { @@ -138,12 +141,14 @@ class DatabasePostgres extends DatabaseBase { return $this->numRows($res = $this->doQuery($SQL)); } - static function newFromParams( $server, $user, $password, $dbName, $flags = 0) { - return new DatabasePostgres( $server, $user, $password, $dbName, $flags ); + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0) + { + return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags ); } /** * Usually aborts on failure + * If the failFunction is set to a non-zero integer, returns success */ function open( $server, $user, $password, $dbName ) { # Test for Postgres support, to avoid suppressed fatal error @@ -183,7 +188,11 @@ class DatabasePostgres extends DatabaseBase { wfDebug( "DB connection error\n" ); wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); wfDebug( $this->lastError()."\n" ); - throw new DBConnectionError( $this, $phpError ); + if ( !$this->mFailFunction ) { + throw new DBConnectionError( $this, $phpError ); + } else { + return false; + } } $this->mOpened = true; diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index e8d1b5adf1..cee84d689a 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -23,8 +23,9 @@ class DatabaseSqlite extends DatabaseBase { * Constructor. * Parameters $server, $user and $password are not used. */ - function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) { + function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) { global $wgSharedDB; + $this->mFailFunction = $failFunction; $this->mFlags = $flags; $this->mName = $dbName; @@ -52,8 +53,8 @@ class DatabaseSqlite extends DatabaseBase { */ function implicitGroupby() { return false; } - static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) { - return new DatabaseSqlite( $server, $user, $password, $dbName, $flags ); + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) { + return new DatabaseSqlite( $server, $user, $password, $dbName, $failFunction, $flags ); } /** Open an SQLite database and return a resource handle to it @@ -89,7 +90,12 @@ class DatabaseSqlite extends DatabaseBase { } if ( $this->mConn === false ) { wfDebug( "DB connection error: $err\n" ); - throw new DBConnectionError( $this, $err ); + if ( !$this->mFailFunction ) { + throw new DBConnectionError( $this, $err ); + } else { + return false; + } + } $this->mOpened = !!$this->mConn; # set error codes only, don't raise exceptions diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index ebb733a0e0..0040fe9e15 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -14,7 +14,7 @@ */ class LoadBalancer { /* private */ var $mServers, $mConns, $mLoads, $mGroupLoads; - /* private */ var $mErrorConnection; + /* private */ var $mFailFunction, $mErrorConnection; /* private */ var $mReadIndex, $mAllowLagged; /* private */ var $mWaitForPos, $mWaitTimeout; /* private */ var $mLaggedSlaveMode, $mLastError = 'Unknown error'; @@ -24,6 +24,7 @@ class LoadBalancer { /** * @param $params Array with keys: * servers Required. Array of server info structures. + * failFunction Deprecated, use exceptions instead. * masterWaitTimeout Replication lag wait timeout * loadMonitor Name of a class used to fetch server lag and load. */ @@ -34,6 +35,11 @@ class LoadBalancer { } $this->mServers = $params['servers']; + if ( isset( $params['failFunction'] ) ) { + $this->mFailFunction = $params['failFunction']; + } else { + $this->mFailFunction = false; + } if ( isset( $params['waitTimeout'] ) ) { $this->mWaitTimeout = $params['waitTimeout']; } else { @@ -67,9 +73,9 @@ class LoadBalancer { } } - static function newFromParams( $servers, $waitTimeout = 10 ) + static function newFromParams( $servers, $failFunction = false, $waitTimeout = 10 ) { - return new LoadBalancer( $servers, $waitTimeout ); + return new LoadBalancer( $servers, $failFunction, $waitTimeout ); } /** @@ -666,11 +672,19 @@ class LoadBalancer { // No last connection, probably due to all servers being too busy wfLogDBError( "LB failure with no last connection\n" ); $conn = new Database; - - // If all servers were busy, mLastError will contain something sensible - throw new DBConnectionError( $conn, $this->mLastError ); + if ( $this->mFailFunction ) { + $conn->failFunction( $this->mFailFunction ); + $conn->reportConnectionError( $this->mLastError ); + } else { + // If all servers were busy, mLastError will contain something sensible + throw new DBConnectionError( $conn, $this->mLastError ); + } } else { - + if ( $this->mFailFunction ) { + $conn->failFunction( $this->mFailFunction ); + } else { + $conn->failFunction( false ); + } $server = $conn->getProperty( 'mServer' ); wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" ); $conn->reportConnectionError( "{$this->mLastError} ({$server})" ); diff --git a/maintenance/tests/SearchUpdateTest.php b/maintenance/tests/SearchUpdateTest.php index fc1c0c4abe..b4299a812e 100644 --- a/maintenance/tests/SearchUpdateTest.php +++ b/maintenance/tests/SearchUpdateTest.php @@ -2,7 +2,7 @@ class DatabaseMock extends DatabaseBase { function __construct( $server = false, $user = false, $password = false, $dbName = false, - $flags = 0, $tablePrefix = 'get from global' ) + $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) { $this->mConn = true; $this->mOpened = true;