Merge "Revision: Assert that $mRecord is never null in Revision"
[lhc/web/wiklou.git] / maintenance / populateChangeTagDef.php
index b11b95f..6c46597 100644 (file)
@@ -34,21 +34,12 @@ class PopulateChangeTagDef extends LoggedUpdateMaintenance {
                $this->setBatchSize( 1000 );
                $this->addOption(
                        'sleep',
-                       'Sleep time (in seconds) between every batch',
+                       'Sleep time (in seconds) between every batch, defaults to zero',
                        false,
                        true
                );
                $this->addOption( 'populate-only', 'Do not update change_tag_def 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();
+               $this->addOption( 'set-user-tags-only', 'Only update ctd_user_defined from valid_tag table' );
        }
 
        protected function doDBUpdates() {
@@ -61,10 +52,15 @@ class PopulateChangeTagDef extends LoggedUpdateMaintenance {
                                __METHOD__
                        )
                ) {
+                       if ( $this->hasOption( 'set-user-tags-only' ) ) {
+                               $this->setUserDefinedTags();
+                               return true;
+                       }
                        if ( !$this->hasOption( 'populate-only' ) ) {
                                $this->updateCountTag();
                        }
                        $this->backpopulateChangeTagId();
+                       $this->setUserDefinedTags();
                } else {
                        $this->updateCountTagId();
                }
@@ -75,6 +71,40 @@ class PopulateChangeTagDef extends LoggedUpdateMaintenance {
                return true;
        }
 
+       private function setUserDefinedTags() {
+               $dbr = $this->lbFactory->getMainLB()->getConnection( DB_REPLICA );
+
+               $userTags = $dbr->selectFieldValues(
+                       'valid_tag',
+                       'vt_tag',
+                       [],
+                       __METHOD__
+               );
+
+               if ( empty( $userTags ) ) {
+                       $this->output( "No user defined tags to set, moving on...\n" );
+                       return;
+               }
+
+               if ( $this->hasOption( 'dry-run' ) ) {
+                       $this->output(
+                               'These tags will have ctd_user_defined=1 : ' . implode( ', ', $userTags ) . "\n"
+                       );
+                       return;
+               }
+
+               $dbw = $this->lbFactory->getMainLB()->getConnection( DB_MASTER );
+
+               $dbw->update(
+                       'change_tag_def',
+                       [ 'ctd_user_defined' => 1 ],
+                       [ 'ctd_name' => $userTags ],
+                       __METHOD__
+               );
+               $this->lbFactory->waitForReplication();
+               $this->output( "Finished setting user defined tags in change_tag_def table\n" );
+       }
+
        private function updateCountTagId() {
                $dbr = $this->lbFactory->getMainLB()->getConnection( DB_REPLICA );
 
@@ -167,7 +197,7 @@ class PopulateChangeTagDef extends LoggedUpdateMaintenance {
        private function backpopulateChangeTagPerTag( $tagName, $tagId ) {
                $dbr = $this->lbFactory->getMainLB()->getConnection( DB_REPLICA );
                $dbw = $this->lbFactory->getMainLB()->getConnection( DB_MASTER );
-               $sleep = (int)$this->getOption( 'sleep', 10 );
+               $sleep = (int)$this->getOption( 'sleep', 0 );
                $lastId = 0;
                $this->output( "Starting to add ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" );
                while ( true ) {