From: jenkins-bot Date: Fri, 16 Sep 2016 01:04:07 +0000 (+0000) Subject: Merge "Remove wfSetBit()/wfSetVar() calls in DatabaseBase" X-Git-Tag: 1.31.0-rc.0~5532 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=5e4f6e1f7f6c9f5fa7534c432b31694a6e4bf265;hp=-c;p=lhc%2Fweb%2Fwiklou.git Merge "Remove wfSetBit()/wfSetVar() calls in DatabaseBase" --- 5e4f6e1f7f6c9f5fa7534c432b31694a6e4bf265 diff --combined includes/db/Database.php index 5d1078a81a,3597b7c8a7..e3344cf2a5 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@@ -60,8 -60,6 +60,8 @@@ abstract class DatabaseBase implements protected $mPassword; /** @var string */ protected $mDBname; + /** @var array[] $aliases Map of (table => (dbname, schema, prefix) map) */ + protected $tableAliases = []; /** @var bool */ protected $cliMode; @@@ -85,7 -83,7 +85,7 @@@ protected $mTrxPreCommitCallbacks = []; /** @var array[] List of (callable, method name) */ protected $mTrxEndCallbacks = []; - /** @var array[] Map of (name => (callable, method name)) */ + /** @var callable[] Map of (name => callable) */ protected $mTrxRecurringCallbacks = []; /** @var bool Whether to suppress triggering of transaction end callbacks */ protected $mTrxEndCallbacksSuppressed = false; @@@ -96,6 -94,8 +96,6 @@@ protected $mSchema; /** @var integer */ protected $mFlags; - /** @var bool */ - protected $mForeign; /** @var array */ protected $mLBInfo = []; /** @var bool|null */ @@@ -263,9 -263,11 +263,9 @@@ $this->mSessionVars = $params['variables']; - $this->mForeign = $params['foreign']; - $this->srvCache = isset( $params['srvCache'] ) ? $params['srvCache'] - : new EmptyBagOStuff(); + : new HashBagOStuff(); $this->profiler = isset( $params['profiler'] ) ? $params['profiler'] @@@ -410,18 -412,25 +410,25 @@@ * - false to disable debugging * - omitted or null to do nothing * - * @return bool|null Previous value of the flag + * @return bool Previous value of the flag + * @deprecated since 1.28; use setFlag() */ public function debug( $debug = null ) { - return wfSetBit( $this->mFlags, DBO_DEBUG, $debug ); + $res = $this->getFlag( DBO_DEBUG ); + if ( $debug !== null ) { + $debug ? $this->setFlag( DBO_DEBUG ) : $this->clearFlag( DBO_DEBUG ); + } + + return $res; } public function bufferResults( $buffer = null ) { - if ( is_null( $buffer ) ) { - return !(bool)( $this->mFlags & DBO_NOBUFFER ); - } else { - return !wfSetBit( $this->mFlags, DBO_NOBUFFER, !$buffer ); + $res = !$this->getFlag( DBO_NOBUFFER ); + if ( $buffer !== null ) { + $buffer ? $this->clearFlag( DBO_NOBUFFER ) : $this->setFlag( DBO_NOBUFFER ); } + + return $res; } /** @@@ -437,7 -446,12 +444,12 @@@ * @return bool The previous value of the flag. */ protected function ignoreErrors( $ignoreErrors = null ) { - return wfSetBit( $this->mFlags, DBO_IGNORE, $ignoreErrors ); + $res = $this->getFlag( DBO_IGNORE ); + if ( $ignoreErrors !== null ) { + $ignoreErrors ? $this->setFlag( DBO_IGNORE ) : $this->clearFlag( DBO_IGNORE ); + } + + return $res; } public function trxLevel() { @@@ -449,11 -463,17 +461,17 @@@ } public function tablePrefix( $prefix = null ) { - return wfSetVar( $this->mTablePrefix, $prefix ); + $old = $this->mTablePrefix; + $this->mTablePrefix = $prefix; + + return $old; } public function dbSchema( $schema = null ) { - return wfSetVar( $this->mSchema, $schema ); + $old = $this->mSchema; + $this->mSchema = $schema; + + return $old; } /** @@@ -665,6 -685,43 +683,6 @@@ } } - /** - * Return a path to the DBMS-specific SQL file if it exists, - * otherwise default SQL file - * - * @param string $filename - * @return string - */ - private function getSqlFilePath( $filename ) { - global $IP; - $dbmsSpecificFilePath = "$IP/maintenance/" . $this->getType() . "/$filename"; - if ( file_exists( $dbmsSpecificFilePath ) ) { - return $dbmsSpecificFilePath; - } else { - return "$IP/maintenance/$filename"; - } - } - - /** - * Return a path to the DBMS-specific schema file, - * otherwise default to tables.sql - * - * @return string - */ - public function getSchemaPath() { - return $this->getSqlFilePath( 'tables.sql' ); - } - - /** - * Return a path to the DBMS-specific update key file, - * otherwise default to update-keys.sql - * - * @return string - */ - public function getUpdateKeysPath() { - return $this->getSqlFilePath( 'update-keys.sql' ); - } - /** * Get information about an index into an object * @param string $table Table name @@@ -1823,6 -1880,7 +1841,6 @@@ * @return string Full database name */ public function tableName( $name, $format = 'quoted' ) { - global $wgSharedDB, $wgSharedPrefix, $wgSharedTables, $wgSharedSchema; # Skip the entire process when we have a string quoted on both ends. # Note that we check the end so that we will still quote any use of # use of `database`.table. But won't break things if someone wants @@@ -1859,14 -1917,14 +1877,14 @@@ $schema = null; } else { list( $table ) = $dbDetails; - if ( $wgSharedDB !== null # We have a shared database - && $this->mForeign == false # We're not working on a foreign database - && !$this->isQuotedIdentifier( $table ) # Prevent shared tables listing '`table`' - && in_array( $table, $wgSharedTables ) # A shared table is selected - ) { - $database = $wgSharedDB; - $schema = $wgSharedSchema === null ? $this->mSchema : $wgSharedSchema; - $prefix = $wgSharedPrefix === null ? $this->mTablePrefix : $wgSharedPrefix; + if ( isset( $this->tableAliases[$table] ) ) { + $database = $this->tableAliases[$table]['dbname']; + $schema = is_string( $this->tableAliases[$table]['schema'] ) + ? $this->tableAliases[$table]['schema'] + : $this->mSchema; + $prefix = is_string( $this->tableAliases[$table]['prefix'] ) + ? $this->tableAliases[$table]['prefix'] + : $this->mTablePrefix; } else { $database = null; $schema = $this->mSchema; # Default schema @@@ -1877,9 -1935,7 +1895,9 @@@ # Quote $table and apply the prefix if not quoted. # $tableName might be empty if this is called from Database::replaceVars() $tableName = "{$prefix}{$table}"; - if ( $format == 'quoted' && !$this->isQuotedIdentifier( $tableName ) && $tableName !== '' ) { + if ( $format == 'quoted' + && !$this->isQuotedIdentifier( $tableName ) && $tableName !== '' + ) { $tableName = $this->addIdentifierQuotes( $tableName ); } @@@ -2671,23 -2727,23 +2689,23 @@@ return false; } - final public function onTransactionResolution( callable $callback ) { + final public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) { if ( !$this->mTrxLevel ) { throw new DBUnexpectedError( $this, "No transaction is active." ); } - $this->mTrxEndCallbacks[] = [ $callback, wfGetCaller() ]; + $this->mTrxEndCallbacks[] = [ $callback, $fname ]; } - final public function onTransactionIdle( callable $callback ) { - $this->mTrxIdleCallbacks[] = [ $callback, wfGetCaller() ]; + final public function onTransactionIdle( callable $callback, $fname = __METHOD__ ) { + $this->mTrxIdleCallbacks[] = [ $callback, $fname ]; if ( !$this->mTrxLevel ) { $this->runOnTransactionIdleCallbacks( self::TRIGGER_IDLE ); } } - final public function onTransactionPreCommitOrIdle( callable $callback ) { + final public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) { if ( $this->mTrxLevel ) { - $this->mTrxPreCommitCallbacks[] = [ $callback, wfGetCaller() ]; + $this->mTrxPreCommitCallbacks[] = [ $callback, $fname ]; } else { // If no transaction is active, then make one for this callback $this->startAtomic( __METHOD__ ); @@@ -2703,7 -2759,7 +2721,7 @@@ final public function setTransactionListener( $name, callable $callback = null ) { if ( $callback ) { - $this->mTrxRecurringCallbacks[$name] = [ $callback, wfGetCaller() ]; + $this->mTrxRecurringCallbacks[$name] = $callback; } else { unset( $this->mTrxRecurringCallbacks[$name] ); } @@@ -2818,8 -2874,9 +2836,8 @@@ /** @var Exception $e */ $e = null; // first exception - foreach ( $this->mTrxRecurringCallbacks as $callback ) { + foreach ( $this->mTrxRecurringCallbacks as $phpCallback ) { try { - list( $phpCallback ) = $callback; $phpCallback( $trigger, $this ); } catch ( Exception $ex ) { call_user_func( $this->errorLogger, $ex ); @@@ -2906,7 -2963,7 +2924,7 @@@ $this->mTrxAutomatic = ( $mode === self::TRANSACTION_INTERNAL ); $this->mTrxAutomaticAtomic = false; $this->mTrxAtomicLevels = []; - $this->mTrxShortId = wfRandomString( 12 ); + $this->mTrxShortId = sprintf( '%06x', mt_rand( 0, 0xffffff ) ); $this->mTrxWriteDuration = 0.0; $this->mTrxWriteQueryCount = 0; $this->mTrxWriteAdjDuration = 0.0; @@@ -3327,6 -3384,25 +3345,6 @@@ return $error; } - /** - * Get the full path of a patch file. Originally based on archive() - * from updaters.inc. Keep in mind this always returns a patch, as - * it fails back to MySQL if no DB-specific patch can be found - * - * @param string $patch The name of the patch, like patch-something.sql - * @return string Full path to patch file - */ - public function patchPath( $patch ) { - global $IP; - - $dbType = $this->getType(); - if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) { - return "$IP/maintenance/$dbType/archives/$patch"; - } else { - return "$IP/maintenance/archives/$patch"; - } - } - public function setSchemaVars( $vars ) { $this->mSchemaVars = $vars; } @@@ -3526,18 -3602,15 +3544,18 @@@ // There is a good chance an exception was thrown, causing any early return // from the caller. Let any error handler get a chance to issue rollback(). // If there isn't one, let the error bubble up and trigger server-side rollback. - $this->onTransactionResolution( function () use ( $lockKey, $fname ) { - $this->unlock( $lockKey, $fname ); - } ); + $this->onTransactionResolution( + function () use ( $lockKey, $fname ) { + $this->unlock( $lockKey, $fname ); + }, + $fname + ); } else { $this->unlock( $lockKey, $fname ); } } ); - $this->commit( __METHOD__, self::FLUSHING_INTERNAL ); + $this->commit( $fname, self::FLUSHING_INTERNAL ); return $unlocker; } @@@ -3631,10 -3704,6 +3649,10 @@@ return is_string( $reason ) ? $reason : false; } + public function setTableAliases( array $aliases ) { + $this->tableAliases = $aliases; + } + /** * @since 1.19 * @return string