Merge "Set migration stage for change tag to read new"
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 1d303c7..0e36009 100644 (file)
@@ -351,13 +351,15 @@ class ChangeTags {
                                foreach ( $tagsToAdd as $tag ) {
                                        $changeTagMapping[$tag] = $changeTagDefStore->acquireId( $tag );
                                }
-
-                               $dbw->update(
-                                       'change_tag_def',
-                                       [ 'ctd_count = ctd_count + 1' ],
-                                       [ 'ctd_name' => $tagsToAdd ],
-                                       __METHOD__
-                               );
+                               // 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 = [];
@@ -408,18 +410,21 @@ class ChangeTags {
                                );
                                $dbw->delete( 'change_tag', $conds, __METHOD__ );
                                if ( $dbw->affectedRows() && $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) {
-                                       $dbw->update(
-                                               'change_tag_def',
-                                               [ 'ctd_count = ctd_count - 1' ],
-                                               [ 'ctd_name' => $tag ],
-                                               __METHOD__
-                                       );
-
-                                       $dbw->delete(
-                                               'change_tag_def',
-                                               [ 'ctd_name' => $tag, 'ctd_count' => 0, 'ctd_user_defined' => 0 ],
-                                               __METHOD__
-                                       );
+                                       // T207881: update the counts at the end of the transaction
+                                       $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tag ) {
+                                               $dbw->update(
+                                                       'change_tag_def',
+                                                       [ 'ctd_count = ctd_count - 1' ],
+                                                       [ 'ctd_name' => $tag ],
+                                                       __METHOD__
+                                               );
+
+                                               $dbw->delete(
+                                                       'change_tag_def',
+                                                       [ 'ctd_name' => $tag, 'ctd_count' => 0, 'ctd_user_defined' => 0 ],
+                                                       __METHOD__
+                                               );
+                                       } );
                                }
                        }
                }
@@ -1585,10 +1590,8 @@ class ChangeTags {
         * @return array Array of string => int
         */
        public static function tagUsageStatistics() {
-               global $wgChangeTagsSchemaMigrationStage, $wgTagStatisticsNewTable;
-               if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ||
-                       ( $wgTagStatisticsNewTable && $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD )
-               ) {
+               global $wgChangeTagsSchemaMigrationStage;
+               if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
                        return self::newTagUsageStatistics();
                }