From: Aaron Schulz Date: Thu, 15 Sep 2016 02:04:21 +0000 (-0700) Subject: Change DatabaseBase => IDatabase in /db where possible X-Git-Tag: 1.31.0-rc.0~5565 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=272f45a8a0a682d903bc521c04cbf0f4bc1e099e;p=lhc%2Fweb%2Fwiklou.git Change DatabaseBase => IDatabase in /db where possible Change-Id: Ia0a049cd4294c5a39aa9ed228d4eb5b15736ea1f --- diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index 97d59d8a96..caca7e2744 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -43,13 +43,13 @@ class CloneDatabase { /** * 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 @@ class CloneDatabase { 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 109dbfea6f..e68a8f25f2 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -231,7 +231,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { /** * 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * @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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { ]; $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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { } public function setLogger( LoggerInterface $logger ) { - $this->quertLogger = $logger; + $this->queryLogger = $logger; } public function getServerInfo() { @@ -494,12 +494,6 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { } } - /** - * 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { # 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * * @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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { $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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { 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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * @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 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface { * @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 269a24873a..2439c60073 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -81,7 +81,7 @@ class DatabaseMssql extends Database { * @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 @@ class DatabaseMssql extends Database { */ 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 1b60ea10cf..af80d24aef 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -1098,7 +1098,7 @@ abstract class DatabaseMysqlBase extends Database { */ 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 f40105815f..5d0ff447ba 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -50,7 +50,7 @@ class ORAResult { } /** - * @param DatabaseBase $db + * @param IDatabase $db * @param resource $stmt A valid OCI statement identifier * @param bool $unique */ @@ -265,7 +265,7 @@ class DatabaseOracle extends Database { * @param string $password * @param string $dbName * @throws DBConnectionError - * @return DatabaseBase|null + * @return resource|null */ function open( $server, $user, $password, $dbName ) { global $wgDBOracleDRCP; diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 22445c0335..b1cc96bc7c 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -26,7 +26,7 @@ class PostgresField implements Field { $has_default, $default; /** - * @param DatabaseBase $db + * @param IDatabase $db * @param string $table * @param string $field * @return null|PostgresField @@ -140,7 +140,7 @@ class SavepointPostgres { protected $didbegin; /** - * @param DatabaseBase $dbw + * @param IDatabase $dbw * @param int $id */ public function __construct( $dbw, $id ) { @@ -276,7 +276,7 @@ class DatabasePostgres extends Database { * @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 ef08ab0705..6bf48e2365 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -277,12 +277,6 @@ class DatabaseSqlite extends Database { 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 aeaa27f50c..2b8c8c6d4b 100644 --- a/includes/db/DatabaseUtility.php +++ b/includes/db/DatabaseUtility.php @@ -78,7 +78,7 @@ class ResultWrapper implements Iterator { /** @var resource */ public $result; - /** @var DatabaseBase */ + /** @var IDatabase */ protected $db; /** @var int */ @@ -90,7 +90,7 @@ class ResultWrapper implements Iterator { /** * 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 de82a1f928..3937dfd059 100644 --- a/includes/db/loadbalancer/LBFactorySingle.php +++ b/includes/db/loadbalancer/LBFactorySingle.php @@ -30,7 +30,7 @@ class LBFactorySingle extends LBFactory { /** * @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 @@ class LBFactorySingle extends LBFactory { * Helper class for LBFactorySingle. */ class LoadBalancerSingle extends LoadBalancer { - /** @var DatabaseBase */ + /** @var IDatabase */ private $db; /** @@ -118,7 +118,7 @@ class LoadBalancerSingle extends LoadBalancer { * @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 8e5902c954..6f136df75e 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -30,7 +30,7 @@ use Psr\Log\LoggerInterface; 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 @@ class LoadBalancer implements ILoadBalancer { /** @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 @@ class LoadBalancer implements ILoadBalancer { /** * 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 @@ class LoadBalancer implements ILoadBalancer { /** * 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 @@ class LoadBalancer implements ILoadBalancer { * * @param int $i Server index * @param string $domain Domain ID to open - * @return DatabaseBase + * @return IDatabase */ private function openForeignConnection( $i, $domain ) { list( $dbName, $prefix ) = explode( '-', $domain, 2 ) + [ '', '' ]; @@ -774,7 +774,7 @@ class LoadBalancer implements ILoadBalancer { * * @param array $server * @param bool $dbNameOverride - * @return DatabaseBase + * @return IDatabase * @throws DBAccessError * @throws MWException */ @@ -806,6 +806,7 @@ class LoadBalancer implements ILoadBalancer { // Set loggers $server['connLogger'] = $this->connLogger; $server['queryLogger'] = $this->queryLogger; + $server['trxProfiler'] = $this->trxProfiler; // Create a live connection object try { @@ -820,7 +821,6 @@ class LoadBalancer implements ILoadBalancer { $db->setLazyMasterHandle( $this->getLazyConnectionRef( DB_MASTER, [], $db->getWikiID() ) ); - $db->setTransactionProfiler( $this->trxProfiler ); if ( $server['serverIndex'] === $this->getWriterIndex() ) { if ( $this->trxRoundId !== false ) { @@ -939,7 +939,7 @@ class LoadBalancer implements ILoadBalancer { } public function closeAll() { - $this->forEachOpenConnection( function ( DatabaseBase $conn ) { + $this->forEachOpenConnection( function ( IDatabase $conn ) { $conn->close(); } ); @@ -976,7 +976,7 @@ class LoadBalancer implements ILoadBalancer { $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 ) { @@ -1021,7 +1021,7 @@ class LoadBalancer implements ILoadBalancer { */ 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). @@ -1103,7 +1103,7 @@ class LoadBalancer implements ILoadBalancer { $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 ); @@ -1177,7 +1177,7 @@ class LoadBalancer implements ILoadBalancer { $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 ); } @@ -1229,7 +1229,7 @@ class LoadBalancer implements ILoadBalancer { * @since 1.28 */ public function flushReplicaSnapshots( $fname = __METHOD__ ) { - $this->forEachOpenReplicaConnection( function ( DatabaseBase $conn ) { + $this->forEachOpenReplicaConnection( function ( IDatabase $conn ) { $conn->flushSnapshot( __METHOD__ ); } ); } @@ -1249,7 +1249,7 @@ class LoadBalancer implements ILoadBalancer { */ public function hasMasterChanges() { $pending = 0; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$pending ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$pending ) { $pending |= $conn->writesOrCallbacksPending(); } ); @@ -1263,7 +1263,7 @@ class LoadBalancer implements ILoadBalancer { */ public function lastMasterChangeTimestamp() { $lastTime = false; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$lastTime ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$lastTime ) { $lastTime = max( $lastTime, $conn->lastDoneWrites() ); } ); @@ -1293,7 +1293,7 @@ class LoadBalancer implements ILoadBalancer { */ public function pendingMasterChangeCallers() { $fnames = []; - $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$fnames ) { + $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$fnames ) { $fnames = array_merge( $fnames, $conn->pendingWriteCallers() ); } ); @@ -1407,7 +1407,7 @@ class LoadBalancer implements ILoadBalancer { public function pingAll() { $success = true; - $this->forEachOpenConnection( function ( DatabaseBase $conn ) use ( &$success ) { + $this->forEachOpenConnection( function ( IDatabase $conn ) use ( &$success ) { if ( !$conn->ping() ) { $success = false; } @@ -1437,7 +1437,7 @@ class LoadBalancer implements ILoadBalancer { $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 ); @@ -1549,7 +1549,7 @@ class LoadBalancer implements ILoadBalancer { } /** - * 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 @@ -1563,7 +1563,7 @@ class LoadBalancer implements ILoadBalancer { 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 f1242e4a4f..671ce993c9 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -157,6 +157,14 @@ interface IDatabase { */ 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 * diff --git a/includes/libs/rdbms/database/RBConnRef.php b/includes/libs/rdbms/database/RBConnRef.php index e606340b91..9035bbd5c9 100644 --- a/includes/libs/rdbms/database/RBConnRef.php +++ b/includes/libs/rdbms/database/RBConnRef.php @@ -81,6 +81,10 @@ class DBConnRef implements IDatabase { 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() ); }