Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/310722
Change subject: Change DatabaseBase => IDatabase in /db where possible ...................................................................... Change DatabaseBase => IDatabase in /db where possible Change-Id: Ia0a049cd4294c5a39aa9ed228d4eb5b15736ea1f --- M includes/db/CloneDatabase.php M includes/db/Database.php M includes/db/DatabaseMssql.php M includes/db/DatabaseMysqlBase.php M includes/db/DatabaseOracle.php M includes/db/DatabasePostgres.php M includes/db/DatabaseSqlite.php M includes/db/DatabaseUtility.php M includes/db/loadbalancer/LBFactorySingle.php M includes/db/loadbalancer/LoadBalancer.php M includes/libs/rdbms/database/IDatabase.php M includes/libs/rdbms/database/RBConnRef.php 12 files changed, 65 insertions(+), 68 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/22/310722/1 diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index 97d59d8..caca7e2 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -43,13 +43,13 @@ /** * Constructor * - * @param DatabaseBase $db A database subclass + * @param IDatabase $db A database subclass * @param array $tablesToClone An array of tables to clone, unprefixed * @param string $newTablePrefix Prefix to assign to the tables * @param string $oldTablePrefix Prefix on current tables, if not $wgDBprefix * @param bool $dropCurrentTables */ - public function __construct( DatabaseBase $db, array $tablesToClone, + public function __construct( IDatabase $db, array $tablesToClone, $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true ) { $this->db = $db; @@ -131,7 +131,7 @@ global $wgDBprefix; wfGetLBFactory()->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) { $lb->setDomainPrefix( $prefix ); - $lb->forEachOpenConnection( function ( DatabaseBase $db ) use ( $prefix ) { + $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix ) { $db->tablePrefix( $prefix ); } ); } ); diff --git a/includes/db/Database.php b/includes/db/Database.php index 109dbfe..e68a8f2 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -231,7 +231,7 @@ * connection object, by specifying no parameters to __construct(). This * feature is deprecated and should be removed. * - * DatabaseBase subclasses should not be constructed directly in external + * IDatabase classes should not be constructed directly in external * code. DatabaseBase::factory() should be used instead. * * @param array $params Parameters passed from DatabaseBase::factory() @@ -301,7 +301,7 @@ /** * Given a DB type, construct the name of the appropriate child class of - * DatabaseBase. This is designed to replace all of the manual stuff like: + * IDatabase. This is designed to replace all of the manual stuff like: * $class = 'Database' . ucfirst( strtolower( $dbType ) ); * as well as validate against the canonical list of DB types we have * @@ -318,8 +318,8 @@ * @param string $dbType A possible DB type * @param array $p An array of options to pass to the constructor. * Valid options are: host, user, password, dbname, flags, tablePrefix, schema, driver - * @throws MWException If the database driver or extension cannot be found - * @return DatabaseBase|null DatabaseBase subclass or null + * @return IDatabase|null If the database driver or extension cannot be found + * @throws MWException */ final public static function factory( $dbType, $p = [] ) { global $wgCommandLineMode; @@ -368,7 +368,7 @@ ]; $class = 'Database' . ucfirst( $driver ); - if ( class_exists( $class ) && is_subclass_of( $class, 'DatabaseBase' ) ) { + if ( class_exists( $class ) && is_subclass_of( $class, 'IDatabase' ) ) { // Resolve some defaults for b/c $p['host'] = isset( $p['host'] ) ? $p['host'] : false; $p['user'] = isset( $p['user'] ) ? $p['user'] : false; @@ -398,7 +398,7 @@ } public function setLogger( LoggerInterface $logger ) { - $this->quertLogger = $logger; + $this->queryLogger = $logger; } public function getServerInfo() { @@ -494,12 +494,6 @@ } } - /** - * Set a lazy-connecting DB handle to the master DB (for replication status purposes) - * - * @param IDatabase $conn - * @since 1.27 - */ public function setLazyMasterHandle( IDatabase $conn ) { $this->lazyMasterHandle = $conn; } @@ -995,9 +989,9 @@ # generalizeSQL() will probably cut down the query to reasonable # logging size most of the time. The substr is really just a sanity check. if ( $isMaster ) { - $queryProf = 'query-m: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 ); + $queryProf = 'query-m: ' . substr( self::generalizeSQL( $sql ), 0, 255 ); } else { - $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 ); + $queryProf = 'query: ' . substr( self::generalizeSQL( $sql ), 0, 255 ); } # Include query transaction state @@ -1132,7 +1126,7 @@ * * @return array */ - protected function prepare( $sql, $func = 'DatabaseBase::prepare' ) { + protected function prepare( $sql, $func = __METHOD__ ) { /* MySQL doesn't support prepared statements (yet), so just * pack up the query for reference. We'll manually replace * the bits later. @@ -1705,7 +1699,7 @@ public function makeList( $a, $mode = LIST_COMMA ) { if ( !is_array( $a ) ) { - throw new DBUnexpectedError( $this, 'DatabaseBase::makeList called with incorrect parameters' ); + throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' ); } $first = true; @@ -2417,8 +2411,7 @@ $fname = __METHOD__ ) { if ( !$conds ) { - throw new DBUnexpectedError( $this, - 'DatabaseBase::deleteJoin() called with empty $conds' ); + throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' ); } $delTable = $this->tableName( $delTable ); @@ -2442,7 +2435,7 @@ public function textFieldSize( $table, $field ) { $table = $this->tableName( $table ); $sql = "SHOW COLUMNS FROM $table LIKE \"$field\";"; - $res = $this->query( $sql, 'DatabaseBase::textFieldSize' ); + $res = $this->query( $sql, __METHOD__ ); $row = $this->fetchObject( $res ); $m = []; @@ -2470,7 +2463,7 @@ public function delete( $table, $conds, $fname = __METHOD__ ) { if ( !$conds ) { - throw new DBUnexpectedError( $this, 'DatabaseBase::delete() called with no conditions' ); + throw new DBUnexpectedError( $this, __METHOD__ . ' called with no conditions' ); } $table = $this->tableName( $table ); @@ -3132,12 +3125,11 @@ public function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) { - throw new RuntimeException( - 'DatabaseBase::duplicateTableStructure is not implemented in descendant class' ); + throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' ); } function listTables( $prefix = null, $fname = __METHOD__ ) { - throw new RuntimeException( 'DatabaseBase::listTables is not implemented in descendant class' ); + throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' ); } /** @@ -3161,7 +3153,7 @@ * @since 1.22 */ public function listViews( $prefix = null, $fname = __METHOD__ ) { - throw new RuntimeException( 'DatabaseBase::listViews is not implemented in descendant class' ); + throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' ); } /** @@ -3173,7 +3165,7 @@ * @since 1.22 */ public function isView( $name ) { - throw new RuntimeException( 'DatabaseBase::isView is not implemented in descendant class' ); + throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' ); } public function timestamp( $ts = 0 ) { diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 269a248..2439c60 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -81,7 +81,7 @@ * @param string $password * @param string $dbName * @throws DBConnectionError - * @return bool|DatabaseBase|null + * @return bool|resource|null */ public function open( $server, $user, $password, $dbName ) { # Test for driver support, to avoid suppressed fatal error @@ -819,8 +819,7 @@ */ public function makeList( $a, $mode = LIST_COMMA, $binaryColumns = [] ) { if ( !is_array( $a ) ) { - throw new DBUnexpectedError( $this, - 'DatabaseBase::makeList called with incorrect parameters' ); + throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' ); } if ( $mode != LIST_NAMES ) { diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 1b60ea1..af80d24 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -1098,7 +1098,7 @@ */ function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__ ) { if ( !$conds ) { - throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' ); + throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' ); } $delTable = $this->tableName( $delTable ); diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index f401058..9c44dc4 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -50,7 +50,7 @@ } /** - * @param DatabaseBase $db + * @param IDatabase $db * @param resource $stmt A valid OCI statement identifier * @param bool $unique */ @@ -265,7 +265,7 @@ * @param string $password * @param string $dbName * @throws DBConnectionError - * @return DatabaseBase|null + * @return resource|bool|null */ function open( $server, $user, $password, $dbName ) { global $wgDBOracleDRCP; diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 22445c0..b1cc96b 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -26,7 +26,7 @@ $has_default, $default; /** - * @param DatabaseBase $db + * @param IDatabase $db * @param string $table * @param string $field * @return null|PostgresField @@ -140,7 +140,7 @@ protected $didbegin; /** - * @param DatabaseBase $dbw + * @param IDatabase $dbw * @param int $id */ public function __construct( $dbw, $id ) { @@ -276,7 +276,7 @@ * @param string $password * @param string $dbName * @throws DBConnectionError|Exception - * @return DatabaseBase|null + * @return resource|bool|null */ function open( $server, $user, $password, $dbName ) { # Test for Postgres support, to avoid suppressed fatal error diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index ef08ab0..6bf48e2 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -277,12 +277,6 @@ return $this->query( "ATTACH DATABASE $file AS $name", $fname ); } - /** - * @see DatabaseBase::isWriteQuery() - * - * @param string $sql - * @return bool - */ function isWriteQuery( $sql ) { return parent::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql ); } diff --git a/includes/db/DatabaseUtility.php b/includes/db/DatabaseUtility.php index aeaa27f..2b8c8c6 100644 --- a/includes/db/DatabaseUtility.php +++ b/includes/db/DatabaseUtility.php @@ -78,7 +78,7 @@ /** @var resource */ public $result; - /** @var DatabaseBase */ + /** @var IDatabase */ protected $db; /** @var int */ @@ -90,7 +90,7 @@ /** * Create a new result object from a result resource and a Database object * - * @param DatabaseBase $database + * @param IDatabase $database * @param resource|ResultWrapper $result */ function __construct( $database, $result ) { diff --git a/includes/db/loadbalancer/LBFactorySingle.php b/includes/db/loadbalancer/LBFactorySingle.php index de82a1f..3937dfd 100644 --- a/includes/db/loadbalancer/LBFactorySingle.php +++ b/includes/db/loadbalancer/LBFactorySingle.php @@ -30,7 +30,7 @@ /** * @param array $conf An associative array with one member: - * - connection: The DatabaseBase connection object + * - connection: The IDatabase connection object */ public function __construct( array $conf ) { parent::__construct( $conf ); @@ -85,7 +85,7 @@ * Helper class for LBFactorySingle. */ class LoadBalancerSingle extends LoadBalancer { - /** @var DatabaseBase */ + /** @var IDatabase */ private $db; /** @@ -118,7 +118,7 @@ * @param string $server * @param bool $dbNameOverride * - * @return DatabaseBase + * @return IDatabase */ protected function reallyOpenConnection( $server, $dbNameOverride = false ) { return $this->db; diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 841231b..153be52 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -30,7 +30,7 @@ class LoadBalancer implements ILoadBalancer { /** @var array[] Map of (server index => server config array) */ private $mServers; - /** @var array[] Map of (local/foreignUsed/foreignFree => server index => DatabaseBase array) */ + /** @var array[] Map of (local/foreignUsed/foreignFree => server index => IDatabase array) */ private $mConns; /** @var array Map of (server index => weight) */ private $mLoads; @@ -62,7 +62,7 @@ /** @var LoggerInterface */ protected $perfLogger; - /** @var bool|DatabaseBase Database connection that caused a problem */ + /** @var bool|IDatabase Database connection that caused a problem */ private $mErrorConnection; /** @var integer The generic (not query grouped) replica DB index (of $mServers) */ private $mReadIndex; @@ -608,7 +608,7 @@ /** * Get a database connection handle reference * - * The handle's methods wrap simply wrap those of a DatabaseBase handle + * The handle's methods wrap simply wrap those of a IDatabase handle * * @see LoadBalancer::getConnection() for parameter information * @@ -625,7 +625,7 @@ /** * Get a database connection handle reference without connecting yet * - * The handle's methods wrap simply wrap those of a DatabaseBase handle + * The handle's methods wrap simply wrap those of a IDatabase handle * * @see LoadBalancer::getConnection() for parameter information * @@ -691,7 +691,7 @@ * * @param int $i Server index * @param string $wiki Wiki ID to open - * @return DatabaseBase + * @return IDatabase */ private function openForeignConnection( $i, $wiki ) { list( $dbName, $prefix ) = explode( '-', $wiki, 2 ) + [ '', '' ]; @@ -774,7 +774,7 @@ * * @param array $server * @param bool $dbNameOverride - * @return DatabaseBase + * @return IDatabase * @throws DBAccessError * @throws MWException */ @@ -805,6 +805,7 @@ // Set loggers $server['connLogger'] = $this->connLogger; $server['queryLogger'] = $this->queryLogger; + $server['trxProfiler'] = $this->trxProfiler; // Create a live connection object try { @@ -819,7 +820,6 @@ $db->setLazyMasterHandle( $this->getLazyConnectionRef( DB_MASTER, [], $db->getWikiID() ) ); - $db->setTransactionProfiler( $this->trxProfiler ); if ( $server['serverIndex'] === $this->getWriterIndex() ) { if ( $this->trxRoundId !== false ) { @@ -938,7 +938,7 @@ } public function closeAll() { - $this->forEachOpenConnection( function ( DatabaseBase $conn ) { + $this->forEachOpenConnection( function ( IDatabase $conn ) { $conn->close(); } ); @@ -975,7 +975,7 @@ $restore = ( $this->trxRoundId !== false ); $this->trxRoundId = false; $this->forEachOpenConnection( - function ( DatabaseBase $conn ) use ( $fname, $restore, &$failures ) { + function ( IDatabase $conn ) use ( $fname, $restore, &$failures ) { try { $conn->commit( $fname, $conn::FLUSHING_ALL_PEERS ); } catch ( DBError $e ) { @@ -1020,7 +1020,7 @@ */ public function approveMasterChanges( array $options ) { $limit = isset( $options['maxWriteDuration'] ) ? $options['maxWriteDuration'] : 0; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( $limit ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( $limit ) { // If atomic sections or explicit transactions are still open, some caller must have // caught an exception but failed to properly rollback any changes. Detect that and // throw and error (causing rollback). @@ -1102,7 +1102,7 @@ $restore = ( $this->trxRoundId !== false ); $this->trxRoundId = false; $this->forEachOpenMasterConnection( - function ( DatabaseBase $conn ) use ( $fname, $restore, &$failures ) { + function ( IDatabase $conn ) use ( $fname, $restore, &$failures ) { try { if ( $conn->writesOrCallbacksPending() ) { $conn->commit( $fname, $conn::FLUSHING_ALL_PEERS ); @@ -1176,7 +1176,7 @@ $restore = ( $this->trxRoundId !== false ); $this->trxRoundId = false; $this->forEachOpenMasterConnection( - function ( DatabaseBase $conn ) use ( $fname, $restore ) { + function ( IDatabase $conn ) use ( $fname, $restore ) { if ( $conn->writesOrCallbacksPending() ) { $conn->rollback( $fname, $conn::FLUSHING_ALL_PEERS ); } @@ -1228,7 +1228,7 @@ * @since 1.28 */ public function flushReplicaSnapshots( $fname = __METHOD__ ) { - $this->forEachOpenReplicaConnection( function ( DatabaseBase $conn ) { + $this->forEachOpenReplicaConnection( function ( IDatabase $conn ) { $conn->flushSnapshot( __METHOD__ ); } ); } @@ -1248,7 +1248,7 @@ */ public function hasMasterChanges() { $pending = 0; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$pending ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$pending ) { $pending |= $conn->writesOrCallbacksPending(); } ); @@ -1262,7 +1262,7 @@ */ public function lastMasterChangeTimestamp() { $lastTime = false; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$lastTime ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$lastTime ) { $lastTime = max( $lastTime, $conn->lastDoneWrites() ); } ); @@ -1292,7 +1292,7 @@ */ public function pendingMasterChangeCallers() { $fnames = []; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$fnames ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$fnames ) { $fnames = array_merge( $fnames, $conn->pendingWriteCallers() ); } ); @@ -1406,7 +1406,7 @@ public function pingAll() { $success = true; - $this->forEachOpenConnection( function ( DatabaseBase $conn ) use ( &$success ) { + $this->forEachOpenConnection( function ( IDatabase $conn ) use ( &$success ) { if ( !$conn->ping() ) { $success = false; } @@ -1436,7 +1436,7 @@ $masterIndex = $this->getWriterIndex(); foreach ( $this->mConns as $connsByServer ) { if ( isset( $connsByServer[$masterIndex] ) ) { - /** @var DatabaseBase $conn */ + /** @var IDatabase $conn */ foreach ( $connsByServer[$masterIndex] as $conn ) { $mergedParams = array_merge( [ $conn ], $params ); call_user_func_array( $callback, $mergedParams ); @@ -1548,7 +1548,7 @@ } /** - * Set a callback via DatabaseBase::setTransactionListener() on + * Set a callback via IDatabase::setTransactionListener() on * all current and future master connections of this load balancer * * @param string $name Callback name @@ -1562,7 +1562,7 @@ unset( $this->trxRecurringCallbacks[$name] ); } $this->forEachOpenMasterConnection( - function ( DatabaseBase $conn ) use ( $name, $callback ) { + function ( IDatabase $conn ) use ( $name, $callback ) { $conn->setTransactionListener( $name, $callback ); } ); diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index f1242e4..671ce99 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -158,6 +158,14 @@ public function setLBInfo( $name, $value = null ); /** + * Set a lazy-connecting DB handle to the master DB (for replication status purposes) + * + * @param IDatabase $conn + * @since 1.27 + */ + public function setLazyMasterHandle( IDatabase $conn ); + + /** * Returns true if this database does an implicit sort when doing GROUP BY * * @return bool diff --git a/includes/libs/rdbms/database/RBConnRef.php b/includes/libs/rdbms/database/RBConnRef.php index e606340..9035bbd 100644 --- a/includes/libs/rdbms/database/RBConnRef.php +++ b/includes/libs/rdbms/database/RBConnRef.php @@ -81,6 +81,10 @@ return $this->__call( __FUNCTION__, func_get_args() ); } + public function setLazyMasterHandle( IDatabase $conn ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + public function implicitGroupby() { return $this->__call( __FUNCTION__, func_get_args() ); } -- To view, visit https://gerrit.wikimedia.org/r/310722 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia0a049cd4294c5a39aa9ed228d4eb5b15736ea1f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits