Merge "Code to read from change_tag_def table instead of valid_tag"
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 45a35c0..8dc63e5 100644 (file)
@@ -928,13 +928,14 @@ class ChangeTags {
                        );
                }
 
-               $dbw->replace(
-                       'valid_tag',
-                       [ 'vt_tag' ],
-                       [ 'vt_tag' => $tag ],
-                       __METHOD__
-               );
-
+               if ( $wgChangeTagsSchemaMigrationStage < MIGRATION_NEW ) {
+                       $dbw->replace(
+                               'valid_tag',
+                               [ 'vt_tag' ],
+                               [ 'vt_tag' => $tag ],
+                               __METHOD__
+                       );
+               }
                // clear the memcache of defined tags
                self::purgeTagCacheAll();
        }
@@ -967,7 +968,9 @@ class ChangeTags {
                        );
                }
 
-               $dbw->delete( 'valid_tag', [ 'vt_tag' => $tag ], __METHOD__ );
+               if ( $wgChangeTagsSchemaMigrationStage < MIGRATION_NEW ) {
+                       $dbw->delete( 'valid_tag', [ 'vt_tag' => $tag ], __METHOD__ );
+               }
 
                // clear the memcache of defined tags
                self::purgeTagCacheAll();
@@ -1458,7 +1461,7 @@ class ChangeTags {
        /**
         * Lists tags explicitly defined in the `valid_tag` table of the database.
         * Tags in table 'change_tag' which are not in table 'valid_tag' are not
-        * included.
+        * included. In case of new backend loads the data from `change_tag_def` table.
         *
         * Tries memcached first.
         *
@@ -1473,11 +1476,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 );
 
-                               $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', [], $fname );
+                               if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
+                                       $tags = self::listExplicitlyDefinedTagsNewBackend();
+                               } else {
+                                       $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', [], $fname );
+                               }
 
                                return array_filter( array_unique( $tags ) );
                        },
@@ -1489,6 +1497,22 @@ 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.