From 02a930d7fbea6fce8f9caa250023e113a9c9ce1c Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Wed, 14 Nov 2018 23:04:29 +0100 Subject: [PATCH] Drop $wgChangeTagsSchemaMigrationStage Bug: T194163 Change-Id: Ieb6cc60cacf9dd0d86641b1be817249cdce42112 --- includes/DefaultSettings.php | 14 - includes/api/ApiQueryAllDeletedRevisions.php | 18 +- includes/api/ApiQueryDeletedRevisions.php | 18 +- includes/api/ApiQueryDeletedrevs.php | 18 +- includes/api/ApiQueryLogEvents.php | 18 +- includes/api/ApiQueryRecentChanges.php | 18 +- includes/api/ApiQueryRevisions.php | 18 +- includes/api/ApiQueryUserContribs.php | 18 +- includes/changetags/ChangeTags.php | 255 ++++------------ maintenance/populateChangeTagDef.php | 10 - tests/phpunit/includes/api/ApiBlockTest.php | 18 -- tests/phpunit/includes/api/ApiDeleteTest.php | 31 -- .../phpunit/includes/api/ApiEditPageTest.php | 19 -- tests/phpunit/includes/api/ApiUnblockTest.php | 19 -- .../includes/api/ApiUserrightsTest.php | 25 -- .../includes/changetags/ChangeTagsTest.php | 201 +----------- .../maintenance/populateChangeTagDefTest.php | 287 ------------------ 17 files changed, 115 insertions(+), 890 deletions(-) delete mode 100644 tests/phpunit/maintenance/populateChangeTagDefTest.php diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 44c53646e2..89cdd4be5a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -9030,20 +9030,6 @@ $wgMultiContentRevisionSchemaMigrationStage = SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_ */ $wgActorTableSchemaMigrationStage = SCHEMA_COMPAT_OLD; -/** - * change_tag table schema migration stage. - * - * - MIGRATION_OLD: Do not use change_tag_def table or ct_tag_id. - * - MIGRATION_WRITE_BOTH: Write to the change_tag_def table and ct_tag_id, but read from - * the old schema. This is different from the formal definition of the constants - * - MIGRATION_WRITE_NEW: Behaves the same as MIGRATION_WRITE_BOTH - * - MIGRATION_NEW: Use the change_tag_def table and ct_tag_id, do not read/write ct_tag - * - * @since 1.32 - * @var int One of the MIGRATION_* constants - */ -$wgChangeTagsSchemaMigrationStage = MIGRATION_NEW; - /** * Flag to enable Partial Blocks. This allows an admin to prevent a user from editing specific pages * or namespaces. diff --git a/includes/api/ApiQueryAllDeletedRevisions.php b/includes/api/ApiQueryAllDeletedRevisions.php index 7b4f15e517..70a77adc39 100644 --- a/includes/api/ApiQueryAllDeletedRevisions.php +++ b/includes/api/ApiQueryAllDeletedRevisions.php @@ -43,8 +43,6 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { * @return void */ protected function run( ApiPageSet $resultPageSet = null ) { - global $wgChangeTagsSchemaMigrationStage; - // Before doing anything at all, let's check permissions $this->checkUserRightsAny( 'deletedhistory' ); @@ -139,16 +137,12 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } diff --git a/includes/api/ApiQueryDeletedRevisions.php b/includes/api/ApiQueryDeletedRevisions.php index 8f71c1c4d7..e7d710d045 100644 --- a/includes/api/ApiQueryDeletedRevisions.php +++ b/includes/api/ApiQueryDeletedRevisions.php @@ -39,8 +39,6 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { } protected function run( ApiPageSet $resultPageSet = null ) { - global $wgChangeTagsSchemaMigrationStage; - $user = $this->getUser(); // Before doing anything at all, let's check permissions $this->checkUserRightsAny( 'deletedhistory' ); @@ -91,16 +89,12 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index e84b9b2247..1da252ecb5 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -36,8 +36,6 @@ class ApiQueryDeletedrevs extends ApiQueryBase { } public function execute() { - global $wgChangeTagsSchemaMigrationStage; - // Before doing anything at all, let's check permissions $this->checkUserRightsAny( 'deletedhistory' ); @@ -145,16 +143,12 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index ba04193b33..edf7002280 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -42,8 +42,6 @@ class ApiQueryLogEvents extends ApiQueryBase { $fld_details = false, $fld_tags = false; public function execute() { - global $wgChangeTagsSchemaMigrationStage; - $params = $this->extractRequestParams(); $db = $this->getDB(); $this->commentStore = CommentStore::getStore(); @@ -116,16 +114,12 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addTables( 'change_tag' ); $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'log_id=ct_log_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index b1dcf0dba1..e33df5cfd0 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -143,8 +143,6 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { * @param ApiPageSet|null $resultPageSet */ public function run( $resultPageSet = null ) { - global $wgChangeTagsSchemaMigrationStage; - $user = $this->getUser(); /* Get the parameters of the request. */ $params = $this->extractRequestParams(); @@ -365,16 +363,12 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { if ( !is_null( $params['tag'] ) ) { $this->addTables( 'change_tag' ); $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index ac7ee0ae9f..a6bf58a1b7 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -84,7 +84,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { } protected function run( ApiPageSet $resultPageSet = null ) { - global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage; + global $wgActorTableSchemaMigrationStage; $params = $this->extractRequestParams( false ); $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); @@ -197,16 +197,12 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rev_id=ct_rev_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } diff --git a/includes/api/ApiQueryUserContribs.php b/includes/api/ApiQueryUserContribs.php index f16f958eb1..ae7c580c2c 100644 --- a/includes/api/ApiQueryUserContribs.php +++ b/includes/api/ApiQueryUserContribs.php @@ -321,7 +321,7 @@ class ApiQueryUserContribs extends ApiQueryBase { * @param int $limit */ private function prepareQuery( array $users, $limit ) { - global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage; + global $wgActorTableSchemaMigrationStage; $this->resetQueryParams(); $db = $this->getDB(); @@ -490,16 +490,12 @@ class ApiQueryUserContribs extends ApiQueryBase { $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ] ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - try { - $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $this->addWhere( '1=0' ); - } - } else { - $this->addWhereFld( 'ct_tag', $this->params['tag'] ); + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + try { + $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $this->addWhere( '1=0' ); } } } diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index c6e8e1fb89..5e83f9509a 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -262,8 +262,6 @@ class ChangeTags { &$rev_id = null, &$log_id = null, $params = null, RecentChange $rc = null, User $user = null ) { - global $wgChangeTagsSchemaMigrationStage; - $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags... $tagsToRemove = array_filter( (array)$tagsToRemove ); @@ -347,35 +345,27 @@ class ChangeTags { $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); if ( count( $tagsToAdd ) ) { $changeTagMapping = []; - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) { - foreach ( $tagsToAdd as $tag ) { - $changeTagMapping[$tag] = $changeTagDefStore->acquireId( $tag ); - } - // T207881: update the counts at the end of the transaction - $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tagsToAdd ) { - $dbw->update( - 'change_tag_def', - [ 'ctd_count = ctd_count + 1' ], - [ 'ctd_name' => $tagsToAdd ], - __METHOD__ - ); - } ); + foreach ( $tagsToAdd as $tag ) { + $changeTagMapping[$tag] = $changeTagDefStore->acquireId( $tag ); } + // T207881: update the counts at the end of the transaction + $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tagsToAdd ) { + $dbw->update( + 'change_tag_def', + [ 'ctd_count = ctd_count + 1' ], + [ 'ctd_name' => $tagsToAdd ], + __METHOD__ + ); + } ); $tagsRows = []; foreach ( $tagsToAdd as $tag ) { - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tagName = null; - } else { - $tagName = $tag; - } // Filter so we don't insert NULLs as zero accidentally. // Keep in mind that $rc_id === null means "I don't care/know about the // rc_id, just delete $tag on this revision/log entry". It doesn't // mean "only delete tags on this revision/log WHERE rc_id IS NULL". $tagsRows[] = array_filter( [ - 'ct_tag' => $tagName, 'ct_rc_id' => $rc_id, 'ct_log_id' => $log_id, 'ct_rev_id' => $rev_id, @@ -392,24 +382,16 @@ class ChangeTags { // delete from change_tag if ( count( $tagsToRemove ) ) { foreach ( $tagsToRemove as $tag ) { - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tagName = null; - $tagId = $changeTagDefStore->getId( $tag ); - } else { - $tagName = $tag; - $tagId = null; - } $conds = array_filter( [ - 'ct_tag' => $tagName, 'ct_rc_id' => $rc_id, 'ct_log_id' => $log_id, 'ct_rev_id' => $rev_id, - 'ct_tag_id' => $tagId, + 'ct_tag_id' => $changeTagDefStore->getId( $tag ), ] ); $dbw->delete( 'change_tag', $conds, __METHOD__ ); - if ( $dbw->affectedRows() && $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) { + if ( $dbw->affectedRows() ) { // T207881: update the counts at the end of the transaction $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tag ) { $dbw->update( @@ -788,7 +770,7 @@ class ChangeTags { public static function modifyDisplayQuery( &$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag = '' ) { - global $wgChangeTagsSchemaMigrationStage, $wgUseTagFilter; + global $wgUseTagFilter; // Normalize to arrays $tables = (array)$tables; @@ -817,24 +799,20 @@ class ChangeTags { $tables[] = 'change_tag'; $join_conds['change_tag'] = [ 'INNER JOIN', $join_cond ]; - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $filterTagIds = []; - $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); - foreach ( (array)$filter_tag as $filterTagName ) { - try { - $filterTagIds[] = $changeTagDefStore->getId( $filterTagName ); - } catch ( NameTableAccessException $exception ) { - // Return nothing. - $conds[] = '0'; - break; - }; - } + $filterTagIds = []; + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + foreach ( (array)$filter_tag as $filterTagName ) { + try { + $filterTagIds[] = $changeTagDefStore->getId( $filterTagName ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $conds[] = '0'; + break; + }; + } - if ( $filterTagIds !== [] ) { - $conds['ct_tag_id'] = $filterTagIds; - } - } else { - $conds['ct_tag'] = $filter_tag; + if ( $filterTagIds !== [] ) { + $conds['ct_tag_id'] = $filterTagIds; } if ( @@ -855,8 +833,6 @@ class ChangeTags { * @throws MWException When unable to determine appropriate JOIN condition for tagging */ public static function makeTagSummarySubquery( $tables ) { - global $wgChangeTagsSchemaMigrationStage; - // Normalize to arrays $tables = (array)$tables; @@ -873,15 +849,9 @@ class ChangeTags { throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' ); } - $tagTables[] = 'change_tag'; - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tagTables[] = 'change_tag_def'; - $join_cond_ts_tags = [ 'change_tag_def' => [ 'INNER JOIN', 'ct_tag_id=ctd_id' ] ]; - $field = 'ctd_name'; - } else { - $field = 'ct_tag'; - $join_cond_ts_tags = []; - } + $tagTables = [ 'change_tag', 'change_tag_def' ]; + $join_cond_ts_tags = [ 'change_tag_def' => [ 'INNER JOIN', 'ct_tag_id=ctd_id' ] ]; + $field = 'ctd_name'; return wfGetDB( DB_REPLICA )->buildGroupConcatField( ',', $tagTables, $field, $join_cond, $join_cond_ts_tags @@ -948,32 +918,20 @@ class ChangeTags { * @since 1.25 */ public static function defineTag( $tag ) { - global $wgChangeTagsSchemaMigrationStage; - $dbw = wfGetDB( DB_MASTER ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) { - $tagDef = [ - 'ctd_name' => $tag, - 'ctd_user_defined' => 1, - 'ctd_count' => 0 - ]; - $dbw->upsert( - 'change_tag_def', - $tagDef, - [ 'ctd_name' ], - [ 'ctd_user_defined' => 1 ], - __METHOD__ - ); - } + $tagDef = [ + 'ctd_name' => $tag, + 'ctd_user_defined' => 1, + 'ctd_count' => 0 + ]; + $dbw->upsert( + 'change_tag_def', + $tagDef, + [ 'ctd_name' ], + [ 'ctd_user_defined' => 1 ], + __METHOD__ + ); - if ( $wgChangeTagsSchemaMigrationStage < MIGRATION_NEW ) { - $dbw->replace( - 'valid_tag', - [ 'vt_tag' ], - [ 'vt_tag' => $tag ], - __METHOD__ - ); - } // clear the memcache of defined tags self::purgeTagCacheAll(); } @@ -987,28 +945,20 @@ class ChangeTags { * @since 1.25 */ public static function undefineTag( $tag ) { - global $wgChangeTagsSchemaMigrationStage; - $dbw = wfGetDB( DB_MASTER ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) { - $dbw->update( - 'change_tag_def', - [ 'ctd_user_defined' => 0 ], - [ 'ctd_name' => $tag ], - __METHOD__ - ); - - $dbw->delete( - 'change_tag_def', - [ 'ctd_name' => $tag, 'ctd_count' => 0 ], - __METHOD__ - ); - } + $dbw->update( + 'change_tag_def', + [ 'ctd_user_defined' => 0 ], + [ 'ctd_name' => $tag ], + __METHOD__ + ); - if ( $wgChangeTagsSchemaMigrationStage < MIGRATION_NEW ) { - $dbw->delete( 'valid_tag', [ 'vt_tag' => $tag ], __METHOD__ ); - } + $dbw->delete( + 'change_tag_def', + [ 'ctd_name' => $tag, 'ctd_count' => 0 ], + __METHOD__ + ); // clear the memcache of defined tags self::purgeTagCacheAll(); @@ -1310,19 +1260,14 @@ class ChangeTags { * @since 1.25 */ public static function deleteTagEverywhere( $tag ) { - global $wgChangeTagsSchemaMigrationStage; $dbw = wfGetDB( DB_MASTER ); $dbw->startAtomic( __METHOD__ ); // delete from valid_tag and/or set ctd_user_defined = 0 self::undefineTag( $tag ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tagId = MediaWikiServices::getInstance()->getChangeTagDefStore()->getId( $tag ); - $conditions = [ 'ct_tag_id' => $tagId ]; - } else { - $conditions = [ 'ct_tag' => $tag ]; - } + $tagId = MediaWikiServices::getInstance()->getChangeTagDefStore()->getId( $tag ); + $conditions = [ 'ct_tag_id' => $tagId ]; // find out which revisions use this tag, so we can delete from tag_summary $result = $dbw->select( 'change_tag', @@ -1338,17 +1283,9 @@ class ChangeTags { } // delete from change_tag - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tagId = MediaWikiServices::getInstance()->getChangeTagDefStore()->getId( $tag ); - $dbw->delete( 'change_tag', [ 'ct_tag_id' => $tagId ], __METHOD__ ); - } else { - $dbw->delete( 'change_tag', [ 'ct_tag' => $tag ], __METHOD__ ); - } - - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) { - $dbw->delete( 'change_tag_def', [ 'ctd_name' => $tag ], __METHOD__ ); - } - + $tagId = MediaWikiServices::getInstance()->getChangeTagDefStore()->getId( $tag ); + $dbw->delete( 'change_tag', [ 'ct_tag_id' => $tagId ], __METHOD__ ); + $dbw->delete( 'change_tag_def', [ 'ctd_name' => $tag ], __METHOD__ ); $dbw->endAtomic( __METHOD__ ); // give extensions a chance @@ -1514,16 +1451,16 @@ class ChangeTags { $cache->makeKey( 'valid-tags-db' ), WANObjectCache::TTL_MINUTE * 5, function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { - global $wgChangeTagsSchemaMigrationStage; $dbr = wfGetDB( DB_REPLICA ); $setOpts += Database::getCacheSetOptions( $dbr ); - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tags = self::listExplicitlyDefinedTagsNewBackend(); - } else { - $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', [], $fname ); - } + $tags = $dbr->selectFieldValues( + 'change_tag_def', + 'ctd_name', + [ 'ctd_user_defined' => 1 ], + __METHOD__ + ); return array_filter( array_unique( $tags ) ); }, @@ -1535,22 +1472,6 @@ class ChangeTags { ); } - /** - * Lists tags explicitly user defined tags. When ctd_user_defined is true. - * - * @return string[] Array of strings: tags - * @since 1.25 - */ - private static function listExplicitlyDefinedTagsNewBackend() { - $dbr = wfGetDB( DB_REPLICA ); - return $dbr->selectFieldValues( - 'change_tag_def', - 'ctd_name', - [ 'ctd_user_defined' => 1 ], - __METHOD__ - ); - } - /** * Lists tags defined by core or extensions using the ListDefinedTags hook. * Extensions need only define those tags they deem to be in active use. @@ -1613,57 +1534,9 @@ class ChangeTags { * Returns a map of any tags used on the wiki to number of edits * tagged with them, ordered descending by the hitcount. * This does not include tags defined somewhere that have never been applied. - * - * Keeps a short-term cache in memory, so calling this multiple times in the - * same request should be fine. - * * @return array Array of string => int */ public static function tagUsageStatistics() { - global $wgChangeTagsSchemaMigrationStage; - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - return self::newTagUsageStatistics(); - } - - $fname = __METHOD__; - $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); - return $cache->getWithSetCallback( - $cache->makeKey( 'change-tag-statistics' ), - WANObjectCache::TTL_MINUTE * 5, - function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { - $dbr = wfGetDB( DB_REPLICA, 'vslow' ); - - $setOpts += Database::getCacheSetOptions( $dbr ); - - $res = $dbr->select( - 'change_tag', - [ 'ct_tag', 'hitcount' => 'count(*)' ], - [], - $fname, - [ 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ] - ); - - $out = []; - foreach ( $res as $row ) { - $out[$row->ct_tag] = $row->hitcount; - } - - return $out; - }, - [ - 'checkKeys' => [ $cache->makeKey( 'change-tag-statistics' ) ], - 'lockTSE' => WANObjectCache::TTL_MINUTE * 5, - 'pcTTL' => WANObjectCache::TTL_PROC_LONG - ] - ); - } - - /** - * Same self::tagUsageStatistics() but uses change_tag_def. - * - * @return array Array of string => int - */ - private static function newTagUsageStatistics() { $dbr = wfGetDB( DB_REPLICA ); $res = $dbr->select( 'change_tag_def', diff --git a/maintenance/populateChangeTagDef.php b/maintenance/populateChangeTagDef.php index 7bec25ac97..9594137de1 100644 --- a/maintenance/populateChangeTagDef.php +++ b/maintenance/populateChangeTagDef.php @@ -42,16 +42,6 @@ class PopulateChangeTagDef extends LoggedUpdateMaintenance { $this->addOption( 'set-user-tags-only', 'Only update ctd_user_defined from valid_tag table' ); } - public function execute() { - global $wgChangeTagsSchemaMigrationStage; - if ( $wgChangeTagsSchemaMigrationStage === MIGRATION_OLD ) { - // Return "success", but don't flag it as done so the next run will retry - $this->output( '... Not run, $wgChangeTagsSchemaMigrationStage === MIGRATION_OLD' . "\n" ); - return true; - } - return parent::execute(); - } - protected function doDBUpdates() { $this->lbFactory = MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $this->setBatchSize( $this->getOption( 'batch-size', $this->getBatchSize() ) ); diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index 563d5e34d8..9898e535e0 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -116,24 +116,6 @@ class ApiBlockTest extends ApiTestCase { } public function testBlockWithTag() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - ChangeTags::defineTag( 'custom tag' ); - - $this->doBlock( [ 'tags' => 'custom tag' ] ); - - $dbw = wfGetDB( DB_MASTER ); - $this->assertSame( 1, (int)$dbw->selectField( - [ 'change_tag', 'logging' ], - 'COUNT(*)', - [ 'log_type' => 'block', 'ct_tag' => 'custom tag' ], - __METHOD__, - [], - [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ] - ) ); - } - - public function testBlockWithTagNewBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); ChangeTags::defineTag( 'custom tag' ); $this->doBlock( [ 'tags' => 'custom tag' ] ); diff --git a/tests/phpunit/includes/api/ApiDeleteTest.php b/tests/phpunit/includes/api/ApiDeleteTest.php index f2db1b2a86..fc546ffbe9 100644 --- a/tests/phpunit/includes/api/ApiDeleteTest.php +++ b/tests/phpunit/includes/api/ApiDeleteTest.php @@ -74,37 +74,6 @@ class ApiDeleteTest extends ApiTestCase { } public function testDeleteWithTag() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $name = 'Help:' . ucfirst( __FUNCTION__ ); - - ChangeTags::defineTag( 'custom tag' ); - - $this->editPage( $name, 'Some text' ); - - $this->doApiRequestWithToken( [ - 'action' => 'delete', - 'title' => $name, - 'tags' => 'custom tag', - ] ); - - $this->assertFalse( Title::newFromText( $name )->exists() ); - - $dbw = wfGetDB( DB_MASTER ); - $this->assertSame( 'custom tag', $dbw->selectField( - [ 'change_tag', 'logging' ], - 'ct_tag', - [ - 'log_namespace' => NS_HELP, - 'log_title' => ucfirst( __FUNCTION__ ), - ], - __METHOD__, - [], - [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ] - ) ); - } - - public function testDeleteWithTagNewBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); $name = 'Help:' . ucfirst( __FUNCTION__ ); ChangeTags::defineTag( 'custom tag' ); diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php index 847316a236..2161093311 100644 --- a/tests/phpunit/includes/api/ApiEditPageTest.php +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -1332,25 +1332,6 @@ class ApiEditPageTest extends ApiTestCase { } public function testEditWithTag() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $name = 'Help:' . ucfirst( __FUNCTION__ ); - - ChangeTags::defineTag( 'custom tag' ); - - $revId = $this->doApiRequestWithToken( [ - 'action' => 'edit', - 'title' => $name, - 'text' => 'Some text', - 'tags' => 'custom tag', - ] )[0]['edit']['newrevid']; - - $dbw = wfGetDB( DB_MASTER ); - $this->assertSame( 'custom tag', $dbw->selectField( - 'change_tag', 'ct_tag', [ 'ct_rev_id' => $revId ], __METHOD__ ) ); - } - - public function testEditWithTagNewBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); $name = 'Help:' . ucfirst( __FUNCTION__ ); ChangeTags::defineTag( 'custom tag' ); diff --git a/tests/phpunit/includes/api/ApiUnblockTest.php b/tests/phpunit/includes/api/ApiUnblockTest.php index 24744df30c..6ebd835cf6 100644 --- a/tests/phpunit/includes/api/ApiUnblockTest.php +++ b/tests/phpunit/includes/api/ApiUnblockTest.php @@ -114,26 +114,7 @@ class ApiUnblockTest extends ApiTestCase { $this->doUnblock( [ 'user' => $this->blocker->getName() ] ); } - // XXX These three tests copy-pasted from ApiBlockTest.php - public function testUnblockWithTag() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - ChangeTags::defineTag( 'custom tag' ); - - $this->doUnblock( [ 'tags' => 'custom tag' ] ); - - $dbw = wfGetDB( DB_MASTER ); - $this->assertSame( 1, (int)$dbw->selectField( - [ 'change_tag', 'logging' ], - 'COUNT(*)', - [ 'log_type' => 'block', 'ct_tag' => 'custom tag' ], - __METHOD__, - [], - [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ] - ) ); - } - public function testUnblockWithTagNewBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); ChangeTags::defineTag( 'custom tag' ); $this->doUnblock( [ 'tags' => 'custom tag' ] ); diff --git a/tests/phpunit/includes/api/ApiUserrightsTest.php b/tests/phpunit/includes/api/ApiUserrightsTest.php index 2534ad3979..8cc021763b 100644 --- a/tests/phpunit/includes/api/ApiUserrightsTest.php +++ b/tests/phpunit/includes/api/ApiUserrightsTest.php @@ -188,31 +188,6 @@ class ApiUserrightsTest extends ApiTestCase { } public function testWithTag() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - ChangeTags::defineTag( 'custom tag' ); - - $user = $this->getMutableTestUser()->getUser(); - - $this->doSuccessfulRightsChange( 'sysop', [ 'tags' => 'custom tag' ], $user ); - - $dbr = wfGetDB( DB_REPLICA ); - $this->assertSame( - 'custom tag', - $dbr->selectField( - [ 'change_tag', 'logging' ], - 'ct_tag', - [ - 'ct_log_id = log_id', - 'log_namespace' => NS_USER, - 'log_title' => strtr( $user->getName(), ' ', '_' ) - ], - __METHOD__ - ) - ); - } - - public function testWithTagNewBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); ChangeTags::defineTag( 'custom tag' ); $user = $this->getMutableTestUser()->getUser(); diff --git a/tests/phpunit/includes/changetags/ChangeTagsTest.php b/tests/phpunit/includes/changetags/ChangeTagsTest.php index cb9dd4145c..8265af801a 100644 --- a/tests/phpunit/includes/changetags/ChangeTagsTest.php +++ b/tests/phpunit/includes/changetags/ChangeTagsTest.php @@ -331,74 +331,10 @@ class ChangeTagsTest extends MediaWikiTestCase { $this->assertEquals( $expected, $actual ); } - public function testUpdateTagsMigrationOld() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_OLD ); - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'change_tag', '*' ); - $dbw->delete( 'change_tag_def', '*' ); - - $rcId = 123; - ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId ); - - $dbr = wfGetDB( DB_REPLICA ); - - $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' ); - $this->assertEquals( [], iterator_to_array( $res, false ) ); - - $expected2 = [ - (object)[ - 'ct_tag' => 'tag1', - 'ct_tag_id' => null, - 'ct_rc_id' => 123 - ], - (object)[ - 'ct_tag' => 'tag2', - 'ct_tag_id' => null, - 'ct_rc_id' => 123 - ], - ]; - $res2 = $dbr->select( 'change_tag', [ 'ct_tag', 'ct_tag_id', 'ct_rc_id' ], '' ); - $this->assertEquals( $expected2, iterator_to_array( $res2, false ) ); - - $rcId = 124; - ChangeTags::updateTags( [ 'tag1', 'tag3' ], [], $rcId ); - - $dbr = wfGetDB( DB_REPLICA ); - - $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' ); - $this->assertEquals( [], iterator_to_array( $res, false ) ); - - $expected2 = [ - (object)[ - 'ct_tag' => 'tag1', - 'ct_tag_id' => null, - 'ct_rc_id' => 123 - ], - (object)[ - 'ct_tag' => 'tag2', - 'ct_tag_id' => null, - 'ct_rc_id' => 123 - ], - (object)[ - 'ct_tag' => 'tag1', - 'ct_tag_id' => null, - 'ct_rc_id' => 124 - ], - (object)[ - 'ct_tag' => 'tag3', - 'ct_tag_id' => null, - 'ct_rc_id' => 124 - ], - ]; - $res2 = $dbr->select( 'change_tag', [ 'ct_tag', 'ct_tag_id', 'ct_rc_id' ], '' ); - $this->assertEquals( $expected2, iterator_to_array( $res2, false ) ); - } - - public function testUpdateTagsMigrationWriteBoth() { + public function testUpdateTags() { // FIXME: fails under postgres $this->markTestSkippedIfDbType( 'postgres' ); - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'change_tag', '*' ); $dbw->delete( 'change_tag_def', '*' ); @@ -425,17 +361,15 @@ class ChangeTagsTest extends MediaWikiTestCase { $expected2 = [ (object)[ - 'ct_tag' => 'tag1', 'ct_tag_id' => 1, 'ct_rc_id' => 123 ], (object)[ - 'ct_tag' => 'tag2', 'ct_tag_id' => 2, 'ct_rc_id' => 123 ], ]; - $res2 = $dbr->select( 'change_tag', [ 'ct_tag', 'ct_tag_id', 'ct_rc_id' ], '' ); + $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' ); $this->assertEquals( $expected2, iterator_to_array( $res2, false ) ); $rcId = 124; @@ -467,59 +401,27 @@ class ChangeTagsTest extends MediaWikiTestCase { $expected2 = [ (object)[ - 'ct_tag' => 'tag1', 'ct_tag_id' => 1, 'ct_rc_id' => 123 ], (object)[ - 'ct_tag' => 'tag2', 'ct_tag_id' => 2, 'ct_rc_id' => 123 ], (object)[ - 'ct_tag' => 'tag1', 'ct_tag_id' => 1, 'ct_rc_id' => 124 ], (object)[ - 'ct_tag' => 'tag3', 'ct_tag_id' => 3, 'ct_rc_id' => 124 ], ]; - $res2 = $dbr->select( 'change_tag', [ 'ct_tag', 'ct_tag_id', 'ct_rc_id' ], '' ); - $this->assertEquals( $expected2, iterator_to_array( $res2, false ) ); - } - - public function testDeleteTagsMigrationOld() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_OLD ); - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'change_tag', '*' ); - $dbw->delete( 'change_tag_def', '*' ); - - $rcId = 123; - ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId ); - - ChangeTags::updateTags( [], [ 'tag2' ], $rcId ); - - $dbr = wfGetDB( DB_REPLICA ); - - $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_id', 'ctd_count' ], '' ); - $this->assertEquals( [], iterator_to_array( $res, false ) ); - - $expected2 = [ - (object)[ - 'ct_tag' => 'tag1', - 'ct_tag_id' => null, - 'ct_rc_id' => 123 - ] - ]; - $res2 = $dbr->select( 'change_tag', [ 'ct_tag', 'ct_tag_id', 'ct_rc_id' ], '' ); + $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' ); $this->assertEquals( $expected2, iterator_to_array( $res2, false ) ); } - public function testDeleteTagsMigrationWriteBoth() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); + public function testDeleteTags() { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'change_tag', '*' ); $dbw->delete( 'change_tag_def', '*' ); @@ -544,54 +446,15 @@ class ChangeTagsTest extends MediaWikiTestCase { $expected2 = [ (object)[ - 'ct_tag' => 'tag1', 'ct_tag_id' => 1, 'ct_rc_id' => 123 ] ]; - $res2 = $dbr->select( 'change_tag', [ 'ct_tag', 'ct_tag_id', 'ct_rc_id' ], '' ); + $res2 = $dbr->select( 'change_tag', [ 'ct_tag_id', 'ct_rc_id' ], '' ); $this->assertEquals( $expected2, iterator_to_array( $res2, false ) ); } - public function testTagUsageStatisticsOldBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_OLD ); - $this->setMwGlobals( 'wgTagStatisticsNewTable', false ); - - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'change_tag', '*' ); - $dbw->delete( 'change_tag_def', '*' ); - - $rcId = 123; - ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId ); - - $rcId = 124; - ChangeTags::updateTags( [ 'tag1' ], [], $rcId ); - - $this->assertEquals( [ 'tag1' => 2, 'tag2' => 1 ], ChangeTags::tagUsageStatistics() ); - } - - public function testTagUsageStatisticsNewMigrationOldBackedn() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $this->setMwGlobals( 'wgTagStatisticsNewTable', false ); - - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'change_tag', '*' ); - $dbw->delete( 'change_tag_def', '*' ); - MediaWikiServices::getInstance()->resetServiceForTesting( 'NameTableStoreFactory' ); - - $rcId = 123; - ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId ); - - $rcId = 124; - ChangeTags::updateTags( [ 'tag1' ], [], $rcId ); - - $this->assertEquals( [ 'tag1' => 2, 'tag2' => 1 ], ChangeTags::tagUsageStatistics() ); - } - - public function testTagUsageStatisticsNewBackend() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $this->setMwGlobals( 'wgTagStatisticsNewTable', true ); - + public function testTagUsageStatistics() { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'change_tag', '*' ); $dbw->delete( 'change_tag_def', '*' ); @@ -606,57 +469,7 @@ class ChangeTagsTest extends MediaWikiTestCase { $this->assertEquals( [ 'tag1' => 2, 'tag2' => 1 ], ChangeTags::tagUsageStatistics() ); } - public function testListExplicitlyDefinedTagsOld() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_OLD ); - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'change_tag', '*' ); - $dbw->delete( 'change_tag_def', '*' ); - $dbw->delete( 'valid_tag', '*' ); - - $rcId = 123; - ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId ); - ChangeTags::defineTag( 'tag2' ); - - $this->assertEquals( [ 'tag2' ], ChangeTags::listExplicitlyDefinedTags() ); - $dbr = wfGetDB( DB_REPLICA ); - $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_user_defined' ], '' ); - $this->assertEquals( [], iterator_to_array( $res, false ) ); - - $this->assertEquals( [ 'tag2' ], $dbr->selectFieldValues( 'valid_tag', 'vt_tag', '' ) ); - } - - public function testListExplicitlyDefinedTagsWriteBoth() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'change_tag', '*' ); - $dbw->delete( 'change_tag_def', '*' ); - $dbw->delete( 'valid_tag', '*' ); - - $rcId = 123; - ChangeTags::updateTags( [ 'tag1', 'tag2' ], [], $rcId ); - ChangeTags::defineTag( 'tag2' ); - - $this->assertEquals( [ 'tag2' ], ChangeTags::listExplicitlyDefinedTags() ); - $dbr = wfGetDB( DB_REPLICA ); - - $expected = [ - (object)[ - 'ctd_name' => 'tag1', - 'ctd_user_defined' => 0 - ], - (object)[ - 'ctd_name' => 'tag2', - 'ctd_user_defined' => 1 - ], - ]; - $res = $dbr->select( 'change_tag_def', [ 'ctd_name', 'ctd_user_defined' ], '' ); - $this->assertEquals( $expected, iterator_to_array( $res, false ) ); - - $this->assertEquals( [ 'tag2' ], $dbr->selectFieldValues( 'valid_tag', 'vt_tag', '' ) ); - } - - public function testListExplicitlyDefinedTagsNew() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); + public function testListExplicitlyDefinedTags() { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'change_tag', '*' ); $dbw->delete( 'change_tag_def', '*' ); diff --git a/tests/phpunit/maintenance/populateChangeTagDefTest.php b/tests/phpunit/maintenance/populateChangeTagDefTest.php deleted file mode 100644 index 8a88f196dd..0000000000 --- a/tests/phpunit/maintenance/populateChangeTagDefTest.php +++ /dev/null @@ -1,287 +0,0 @@ -tablesUsed = [ 'change_tag', 'change_tag_def', 'updatelog' ]; - - $this->cleanChangeTagTables(); - $this->insertChangeTagData(); - } - - private function cleanChangeTagTables() { - wfGetDB( DB_MASTER )->delete( 'change_tag', '*' ); - wfGetDB( DB_MASTER )->delete( 'change_tag_def', '*' ); - wfGetDB( DB_MASTER )->delete( 'updatelog', '*' ); - } - - private function insertChangeTagData() { - $changeTags = []; - - $changeTags[] = [ - 'ct_rc_id' => 1234, - 'ct_tag' => 'One Tag', - ]; - - $changeTags[] = [ - 'ct_rc_id' => 1235, - 'ct_tag' => 'Two Tags', - ]; - - $changeTags[] = [ - 'ct_log_id' => 1236, - 'ct_tag' => 'Two Tags', - ]; - - $changeTags[] = [ - 'ct_rev_id' => 1237, - 'ct_tag' => 'Three Tags', - ]; - - $changeTags[] = [ - 'ct_rc_id' => 1238, - 'ct_tag' => 'Three Tags', - ]; - - $changeTags[] = [ - 'ct_log_id' => 1239, - 'ct_tag' => 'Three Tags', - ]; - - wfGetDB( DB_MASTER )->insert( 'change_tag', $changeTags ); - } - - public function testRun() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $this->maintenance->loadWithArgv( [ '--sleep', '0' ] ); - - $this->maintenance->execute(); - - $changeTagDefRows = [ - (object)[ - 'ctd_name' => 'One Tag', - 'ctd_count' => 1, - ], - (object)[ - 'ctd_name' => 'Two Tags', - 'ctd_count' => 2, - ], - (object)[ - 'ctd_name' => 'Three Tags', - 'ctd_count' => 3, - ], - ]; - - $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select( - [ 'change_tag_def' ], - [ 'ctd_name', 'ctd_count' ], - [], - __METHOD__, - [ 'ORDER BY' => 'ctd_count' ] - ); - - $this->assertEquals( $changeTagDefRows, iterator_to_array( $actualChangeTagDefs, false ) ); - - // Check if change_tag is also backpopulated - $actualChangeTags = wfGetDB( DB_REPLICA )->select( - [ 'change_tag', 'change_tag_def' ], - [ 'ct_tag', 'ct_tag_id', 'ctd_count' ], - [], - __METHOD__, - [], - [ 'change_tag_def' => [ 'LEFT JOIN', 'ct_tag_id=ctd_id' ] ] - ); - $mapping = [ - 'One Tag' => 1, - 'Two Tags' => 2, - 'Three Tags' => 3 - ]; - foreach ( $actualChangeTags as $row ) { - $this->assertNotNull( $row->ct_tag_id ); - $this->assertEquals( $row->ctd_count, $mapping[$row->ct_tag] ); - } - } - - public function testRunUpdateHitCountMigrationNew() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); - $changeTagDefBadRows = [ - [ - 'ctd_name' => 'One Tag', - 'ctd_user_defined' => 0, - 'ctd_count' => 50, - ], - [ - 'ctd_name' => 'Two Tags', - 'ctd_user_defined' => 0, - 'ctd_count' => 4, - ], - [ - 'ctd_name' => 'Three Tags', - 'ctd_user_defined' => 0, - 'ctd_count' => 3, - ], - ]; - wfGetDB( DB_MASTER )->insert( - 'change_tag_def', - $changeTagDefBadRows - ); - - $mapping = [ - 'One Tag' => 1, - 'Two Tags' => 2, - 'Three Tags' => 3 - ]; - foreach ( $mapping as $tagName => $tagId ) { - wfGetDB( DB_MASTER )->update( - 'change_tag', - [ 'ct_tag_id' => $tagId ], - [ 'ct_tag' => $tagName ] - ); - } - - $this->maintenance->loadWithArgv( [ '--sleep', '0' ] ); - - $this->maintenance->execute(); - - $changeTagDefRows = [ - (object)[ - 'ctd_name' => 'One Tag', - 'ctd_count' => 1, - ], - (object)[ - 'ctd_name' => 'Two Tags', - 'ctd_count' => 2, - ], - (object)[ - 'ctd_name' => 'Three Tags', - 'ctd_count' => 3, - ], - ]; - - $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select( - [ 'change_tag_def' ], - [ 'ctd_name', 'ctd_count' ], - [], - __METHOD__, - [ 'ORDER BY' => 'ctd_count' ] - ); - - $this->assertEquals( $changeTagDefRows, iterator_to_array( $actualChangeTagDefs, false ) ); - } - - public function testRunUpdateHitCountMigrationWriteBoth() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $changeTagDefBadRows = [ - [ - 'ctd_name' => 'One Tag', - 'ctd_user_defined' => 0, - 'ctd_count' => 50, - ], - [ - 'ctd_name' => 'Two Tags', - 'ctd_user_defined' => 0, - 'ctd_count' => 4, - ], - [ - 'ctd_name' => 'Three Tags', - 'ctd_user_defined' => 0, - 'ctd_count' => 3, - ], - ]; - wfGetDB( DB_MASTER )->insert( - 'change_tag_def', - $changeTagDefBadRows - ); - - $this->maintenance->loadWithArgv( [ '--sleep', '0' ] ); - - $this->maintenance->execute(); - - $changeTagDefRows = [ - (object)[ - 'ctd_name' => 'One Tag', - 'ctd_count' => 1, - ], - (object)[ - 'ctd_name' => 'Two Tags', - 'ctd_count' => 2, - ], - (object)[ - 'ctd_name' => 'Three Tags', - 'ctd_count' => 3, - ], - ]; - - $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select( - [ 'change_tag_def' ], - [ 'ctd_name', 'ctd_count' ], - [], - __METHOD__, - [ 'ORDER BY' => 'ctd_count' ] - ); - - $this->assertEquals( $changeTagDefRows, iterator_to_array( $actualChangeTagDefs, false ) ); - } - - public function testDryRunMigrationNew() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW ); - $this->maintenance->loadWithArgv( [ '--dry-run', '--sleep', '0' ] ); - - $this->maintenance->execute(); - - $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select( - [ 'change_tag_def' ], - [ 'ctd_id', 'ctd_name' ] - ); - - $this->assertEquals( [], iterator_to_array( $actualChangeTagDefs, false ) ); - - $actualChangeTags = wfGetDB( DB_REPLICA )->select( - [ 'change_tag' ], - [ 'ct_tag_id', 'ct_tag' ] - ); - - foreach ( $actualChangeTags as $row ) { - $this->assertNull( $row->ct_tag_id ); - $this->assertNotNull( $row->ct_tag ); - } - } - - public function testDryRunMigrationWriteBoth() { - $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH ); - $this->maintenance->loadWithArgv( [ '--dry-run', '--sleep', '0' ] ); - - $this->maintenance->execute(); - - $actualChangeTagDefs = wfGetDB( DB_REPLICA )->select( - [ 'change_tag_def' ], - [ 'ctd_id', 'ctd_name' ] - ); - - $this->assertEquals( [], iterator_to_array( $actualChangeTagDefs, false ) ); - - $actualChangeTags = wfGetDB( DB_REPLICA )->select( - [ 'change_tag' ], - [ 'ct_tag_id', 'ct_tag' ] - ); - - foreach ( $actualChangeTags as $row ) { - $this->assertNull( $row->ct_tag_id ); - $this->assertNotNull( $row->ct_tag ); - } - } - -} -- 2.20.1