Aaron Schulz has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/345706 )
Change subject: Use IDatabase type hints in /maintenance ...................................................................... Use IDatabase type hints in /maintenance Relatedly, move lockTables()/unlockTables() to IMaintainableDatabase Change-Id: Ib53e9fa948deb2f9a70f0ce16c002613d0060bf9 --- M includes/libs/rdbms/database/Database.php M includes/libs/rdbms/database/IMaintainableDatabase.php M includes/libs/rdbms/database/MaintainableDBConnRef.php M maintenance/Maintenance.php M maintenance/archives/upgradeLogging.php M maintenance/benchmarks/bench_delete_truncate.php M maintenance/convertUserOptions.php M maintenance/deleteOrphanedRevisions.php M maintenance/deleteRevision.php M maintenance/dumpIterator.php M maintenance/dumpTextPass.php M maintenance/fetchText.php M maintenance/namespaceDupes.php M maintenance/orphans.php M maintenance/populateContentModel.php M maintenance/populateRecentChangesSource.php M maintenance/rebuildImages.php M maintenance/rebuildtextindex.php M maintenance/refreshImageMetadata.php M maintenance/refreshLinks.php M maintenance/sql.php M maintenance/update.php M maintenance/updateCollation.php 23 files changed, 97 insertions(+), 54 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/06/345706/1 diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index fbfd899..90ebc45 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -3306,25 +3306,10 @@ return false; } - /** - * Lock specific tables - * - * @param array $read Array of tables to lock for read access - * @param array $write Array of tables to lock for write access - * @param string $method Name of caller - * @param bool $lowPriority Whether to indicate writes to be LOW PRIORITY - * @return bool - */ public function lockTables( $read, $write, $method, $lowPriority = true ) { return true; } - /** - * Unlock specific tables - * - * @param string $method The caller - * @return bool - */ public function unlockTables( $method ) { return true; } diff --git a/includes/libs/rdbms/database/IMaintainableDatabase.php b/includes/libs/rdbms/database/IMaintainableDatabase.php index 138cf2d..2c4a0d0 100644 --- a/includes/libs/rdbms/database/IMaintainableDatabase.php +++ b/includes/libs/rdbms/database/IMaintainableDatabase.php @@ -210,6 +210,31 @@ public function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ); + + /** + * Lock specific tables + * + * Only use this method within a transaction + * + * @param array $read Array of tables to lock for read access + * @param array $write Array of tables to lock for write access + * @param string $method Name of caller + * @param bool $lowPriority Whether to indicate writes to be LOW PRIORITY + * @return bool + * @since 1.29 + */ + public function lockTables( $read, $write, $method, $lowPriority = true ); + + /** + * Unlock specific tables + * + * Only use this method within a transaction + * + * @param string $method The caller + * @return bool + * @since 1.29 + */ + public function unlockTables( $method ); } class_alias( 'Wikimedia\Rdbms\IMaintainableDatabase', 'IMaintainableDatabase' ); diff --git a/includes/libs/rdbms/database/MaintainableDBConnRef.php b/includes/libs/rdbms/database/MaintainableDBConnRef.php index 30c62de..aedd5ed 100644 --- a/includes/libs/rdbms/database/MaintainableDBConnRef.php +++ b/includes/libs/rdbms/database/MaintainableDBConnRef.php @@ -68,6 +68,14 @@ ) { return $this->__call( __FUNCTION__, func_get_args() ); } + + public function lockTables( $read, $write, $method, $lowPriority = true ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } + + public function unlockTables( $method ) { + return $this->__call( __FUNCTION__, func_get_args() ); + } } class_alias( 'Wikimedia\Rdbms\MaintainableDBConnRef', 'MaintainableDBConnRef' ); diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index a8080c5..e5ba411 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -40,6 +40,7 @@ use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\LBFactory; +use Wikimedia\Rdbms\IMaintainableDatabase; /** * Abstract maintenance class for quickly writing and churning out @@ -106,7 +107,7 @@ /** * Used by getDB() / setDB() - * @var Database + * @var IMaintainableDatabase */ private $mDb = null; @@ -206,7 +207,7 @@ * @param string $description The description of the param to show on --help * @param bool $required Is the param required? * @param bool $withArg Is an argument required with this option? - * @param string $shortName Character to use as short name + * @param string|bool $shortName Character to use as short name * @param bool $multiOccurrence Can this option be passed multiple times? */ protected function addOption( $name, $description, $required = false, @@ -1243,7 +1244,7 @@ * @param integer $db DB index (DB_REPLICA/DB_MASTER) * @param array $groups; default: empty array * @param string|bool $wiki; default: current wiki - * @return Database + * @return IMaintainableDatabase */ protected function getDB( $db, $groups = [], $wiki = false ) { if ( is_null( $this->mDb ) ) { @@ -1256,7 +1257,7 @@ /** * Sets database object to be returned by getDB(). * - * @param IDatabase $db Database object to be used + * @param IDatabase $db */ public function setDB( IDatabase $db ) { $this->mDb = $db; @@ -1318,7 +1319,7 @@ /** * Lock the search index - * @param Database &$db + * @param IMaintainableDatabase &$db */ private function lockSearchindex( $db ) { $write = [ 'searchindex' ]; @@ -1336,7 +1337,7 @@ /** * Unlock the tables - * @param Database &$db + * @param IMaintainableDatabase &$db */ private function unlockSearchindex( $db ) { $db->unlockTables( __CLASS__ . '::' . __METHOD__ ); @@ -1345,7 +1346,7 @@ /** * Unlock and lock again * Since the lock is low-priority, queued reads will be able to complete - * @param Database &$db + * @param IMaintainableDatabase &$db */ private function relockSearchindex( $db ) { $this->unlockSearchindex( $db ); @@ -1356,7 +1357,7 @@ * Perform a search index update with locking * @param int $maxLockTime The maximum time to keep the search index locked. * @param string $callback The function that will update the function. - * @param Database $dbw + * @param IMaintainableDatabase $dbw * @param array $results */ public function updateSearchIndex( $maxLockTime, $callback, $dbw, $results ) { @@ -1392,7 +1393,7 @@ /** * Update the searchindex table for a given pageid - * @param Database $dbw A database write handle + * @param IDatabase $dbw A database write handle * @param int $pageId The page ID to update. * @return null|string */ diff --git a/maintenance/archives/upgradeLogging.php b/maintenance/archives/upgradeLogging.php index 0beff7c..231f137 100644 --- a/maintenance/archives/upgradeLogging.php +++ b/maintenance/archives/upgradeLogging.php @@ -23,16 +23,18 @@ require __DIR__ . '/../commandLine.inc'; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script that upgrade for log_id/log_deleted fields in a * replication-safe way. * * @ingroup Maintenance */ -class UpdateLogging { +class UpdateLogging extends Maintenance { /** - * @var Database + * @var IMaintainableDatabase */ public $dbw; public $batchSize = 1000; diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php index 2a8d79a..9170eba 100644 --- a/maintenance/benchmarks/bench_delete_truncate.php +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -69,7 +69,7 @@ } /** - * @param Database $dbw + * @param IDatabase $dbw * @return void */ private function insertData( $dbw ) { @@ -82,7 +82,7 @@ } /** - * @param Database $dbw + * @param IDatabase $dbw * @return void */ private function delete( $dbw ) { @@ -90,7 +90,7 @@ } /** - * @param Database $dbw + * @param IDatabase $dbw * @return void */ private function truncate( $dbw ) { diff --git a/maintenance/convertUserOptions.php b/maintenance/convertUserOptions.php index 70f3654..675d069 100644 --- a/maintenance/convertUserOptions.php +++ b/maintenance/convertUserOptions.php @@ -24,6 +24,7 @@ require_once __DIR__ . '/Maintenance.php'; use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IDatabase; /** * Maintenance script to convert user options to the new `user_properties` table. @@ -76,7 +77,7 @@ /** * @param ResultWrapper $res - * @param Database $dbw + * @param IDatabase $dbw * @return null|int */ function convertOptionBatch( $res, $dbw ) { diff --git a/maintenance/deleteOrphanedRevisions.php b/maintenance/deleteOrphanedRevisions.php index df496d4..e99f2b0 100644 --- a/maintenance/deleteOrphanedRevisions.php +++ b/maintenance/deleteOrphanedRevisions.php @@ -26,6 +26,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; + /** * Maintenance script that deletes revisions which refer to a nonexisting page. * @@ -83,7 +85,7 @@ * Do this inside a transaction * * @param array $id Array of revision id values - * @param Database $dbw Database class (needs to be a master) + * @param IDatabase $dbw Master DB handle */ private function deleteRevs( $id, &$dbw ) { if ( !is_array( $id ) ) { diff --git a/maintenance/deleteRevision.php b/maintenance/deleteRevision.php index 0111ac5..3abbdab 100644 --- a/maintenance/deleteRevision.php +++ b/maintenance/deleteRevision.php @@ -86,7 +86,6 @@ ); $dbw->delete( 'revision', [ 'rev_id' => $revID ] ); if ( $pageLatest == $revID ) { - // Database integrity $newLatest = $dbw->selectField( 'revision', 'rev_id', diff --git a/maintenance/dumpIterator.php b/maintenance/dumpIterator.php index 9f983c1..6dbad94 100644 --- a/maintenance/dumpIterator.php +++ b/maintenance/dumpIterator.php @@ -117,7 +117,7 @@ /** * Callback function for each revision, child classes should override * processRevision instead. - * @param Database $rev + * @param WikiRevision $rev */ public function handleRevision( $rev ) { $title = $rev->getTitle(); diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 5d92eec..581f0d7 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -27,7 +27,7 @@ require_once __DIR__ . '/backup.inc'; require_once __DIR__ . '/../includes/export/WikiExporter.php'; -use Wikimedia\Rdbms\LoadBalancer; +use Wikimedia\Rdbms\IMaintainableDatabase; /** * @ingroup Maintenance @@ -88,7 +88,7 @@ protected $checkpointFiles = []; /** - * @var Database + * @var IMaintainableDatabase */ protected $db; diff --git a/maintenance/fetchText.php b/maintenance/fetchText.php index 9dee6e5..9c5a375 100644 --- a/maintenance/fetchText.php +++ b/maintenance/fetchText.php @@ -24,6 +24,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; + /** * Maintenance script used to fetch page text in a subprocess. * @@ -71,7 +73,7 @@ /** * May throw a database error if, say, the server dies during query. - * @param Database $db + * @param IDatabase $db * @param int $id The old_id * @return string */ diff --git a/maintenance/namespaceDupes.php b/maintenance/namespaceDupes.php index 80e8011..0bd627f 100644 --- a/maintenance/namespaceDupes.php +++ b/maintenance/namespaceDupes.php @@ -24,11 +24,12 @@ * @ingroup Maintenance */ +require_once __DIR__ . '/Maintenance.php'; + use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\ResultWrapper; - -require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IMaintainableDatabase; /** * Maintenance script that checks for articles to fix after @@ -39,7 +40,7 @@ class NamespaceConflictChecker extends Maintenance { /** - * @var Database + * @var IMaintainableDatabase */ protected $db; diff --git a/maintenance/orphans.php b/maintenance/orphans.php index 2da8830..e36c5b6 100644 --- a/maintenance/orphans.php +++ b/maintenance/orphans.php @@ -30,6 +30,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script that looks for 'orphan' revisions hooked to pages which * don't exist and 'childless' pages with no revisions. @@ -56,7 +58,7 @@ /** * Lock the appropriate tables for the script - * @param Database $db + * @param IMaintainableDatabase $db * @param string[] $extraTable The name of any extra tables to lock (eg: text) */ private function lockTables( $db, $extraTable = [] ) { diff --git a/maintenance/populateContentModel.php b/maintenance/populateContentModel.php index b41e0e0..7d83180 100644 --- a/maintenance/populateContentModel.php +++ b/maintenance/populateContentModel.php @@ -23,13 +23,15 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; + /** * Usage: * populateContentModel.php --ns=1 --table=page */ class PopulateContentModel extends Maintenance { protected $wikiId; - + /** @var WANObjectCache */ protected $wanCache; public function __construct() { @@ -78,7 +80,7 @@ $this->wanCache->delete( $revisionKey ); } - private function updatePageRows( Database $dbw, $pageIds, $model ) { + private function updatePageRows( IDatabase $dbw, $pageIds, $model ) { $count = count( $pageIds ); $this->output( "Setting $count rows to $model..." ); $dbw->update( @@ -91,7 +93,7 @@ $this->output( "done.\n" ); } - protected function populatePage( Database $dbw, $ns ) { + protected function populatePage( IDatabase $dbw, $ns ) { $toSave = []; $lastId = 0; $nsCondition = $ns === 'all' ? [] : [ 'page_namespace' => $ns ]; @@ -123,7 +125,7 @@ } } - private function updateRevisionOrArchiveRows( Database $dbw, $ids, $model, $table ) { + private function updateRevisionOrArchiveRows( IDatabase $dbw, $ids, $model, $table ) { $prefix = $table === 'archive' ? 'ar' : 'rev'; $model_column = "{$prefix}_content_model"; $format_column = "{$prefix}_content_format"; @@ -142,7 +144,7 @@ $this->output( "done.\n" ); } - protected function populateRevisionOrArchive( Database $dbw, $table, $ns ) { + protected function populateRevisionOrArchive( IDatabase $dbw, $table, $ns ) { $prefix = $table === 'archive' ? 'ar' : 'rev'; $model_column = "{$prefix}_content_model"; $format_column = "{$prefix}_content_format"; diff --git a/maintenance/populateRecentChangesSource.php b/maintenance/populateRecentChangesSource.php index ac87cf3..5d5da89 100644 --- a/maintenance/populateRecentChangesSource.php +++ b/maintenance/populateRecentChangesSource.php @@ -23,6 +23,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; + /** * Maintenance script to populate the rc_source field. * @@ -83,7 +85,7 @@ return __CLASS__; } - protected function buildUpdateCondition( Database $dbw ) { + protected function buildUpdateCondition( IDatabase $dbw ) { $rcNew = $dbw->addQuotes( RC_NEW ); $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW ); $rcEdit = $dbw->addQuotes( RC_EDIT ); diff --git a/maintenance/rebuildImages.php b/maintenance/rebuildImages.php index 6aa1f37..966864e 100644 --- a/maintenance/rebuildImages.php +++ b/maintenance/rebuildImages.php @@ -32,6 +32,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script to update image metadata records. * @@ -40,7 +42,7 @@ class ImageBuilder extends Maintenance { /** - * @var Database + * @var IMaintainableDatabase */ protected $dbw; diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index b7f0762..e4bb60e 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -27,6 +27,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script that rebuilds search index table from scratch. * @@ -36,7 +38,7 @@ const RTI_CHUNK_SIZE = 500; /** - * @var Database + * @var IMaintainableDatabase */ private $db; diff --git a/maintenance/refreshImageMetadata.php b/maintenance/refreshImageMetadata.php index 372c352..b557f3d 100644 --- a/maintenance/refreshImageMetadata.php +++ b/maintenance/refreshImageMetadata.php @@ -29,6 +29,9 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script to refresh image metadata fields. * @@ -37,7 +40,7 @@ class RefreshImageMetadata extends Maintenance { /** - * @var Database + * @var IMaintainableDatabase */ protected $dbw; @@ -205,7 +208,7 @@ } /** - * @param Database $dbw + * @param IDatabase $dbw * @return array */ function getConditions( $dbw ) { diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index 67f7780..a6cd548 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -390,7 +390,7 @@ * By specifying a null $start or $end, it is also possible to create * half-bounded or unbounded intervals using this function. * - * @param IDatabase $db Database connection + * @param IDatabase $db * @param string $var Field name * @param mixed $start First value to include or null * @param mixed $end Last value to include or null diff --git a/maintenance/sql.php b/maintenance/sql.php index b03620d..70f9aaa 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -77,7 +77,7 @@ $index = DB_MASTER; } - /** @var Database $db DB handle for the appropriate cluster/wiki */ + /** @var IDatabase $db DB handle for the appropriate cluster/wiki */ $db = $lb->getConnection( $index, [], $wiki ); if ( $replicaDB != '' && $db->getLBInfo( 'master' ) !== null ) { $this->error( "The server selected ({$db->getServer()}) is not a replica DB.", 1 ); diff --git a/maintenance/update.php b/maintenance/update.php index d96cecd..5f705ba 100755 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -27,6 +27,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Maintenance script to run database schema updates. * @@ -145,7 +147,7 @@ $this->output( "Going to run database updates for " . wfWikiID() . "\n" ); if ( $db->getType() === 'sqlite' ) { - /** @var Database|DatabaseSqlite $db */ + /** @var IMaintainableDatabase|DatabaseSqlite $db */ $this->output( "Using SQLite file: '{$db->getDbFilePath()}'\n" ); } $this->output( "Depending on the size of your database this may take a while!\n" ); diff --git a/maintenance/updateCollation.php b/maintenance/updateCollation.php index e70a176..84fc2d2 100644 --- a/maintenance/updateCollation.php +++ b/maintenance/updateCollation.php @@ -26,6 +26,8 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; + /** * Maintenance script that will find all rows in the categorylinks table * whose collation is out-of-date. @@ -242,7 +244,7 @@ * Return an SQL expression selecting rows which sort above the given row, * assuming an ordering of cl_collation, cl_to, cl_type, cl_from * @param stdClass $row - * @param Database $dbw + * @param IDatabase $dbw * @return string */ function getBatchCondition( $row, $dbw ) { -- To view, visit https://gerrit.wikimedia.org/r/345706 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib53e9fa948deb2f9a70f0ce16c002613d0060bf9 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