resourceloader: Audit use of JSON encoding and use json_encode directly
[lhc/web/wiklou.git] / maintenance / populateChangeTagDef.php
index 3b32c00..b06ac2b 100644 (file)
@@ -38,6 +38,7 @@ class PopulateChangeTagDef extends Maintenance {
                        false,
                        true
                );
+               $this->addOption( 'populate-only', 'Do not update change_tag_def table' );
        }
 
        public function execute() {
@@ -47,7 +48,9 @@ class PopulateChangeTagDef extends Maintenance {
 
                $this->countDown( 5 );
                if ( $wgChangeTagsSchemaMigrationStage < MIGRATION_NEW ) {
-                       $this->updateCountTag();
+                       if ( !$this->hasOption( 'populate-only' ) ) {
+                               $this->updateCountTag();
+                       }
                        $this->backpopulateChangeTagId();
                } else {
                        $this->updateCountTagId();
@@ -137,7 +140,8 @@ class PopulateChangeTagDef extends Maintenance {
                        'change_tag_def',
                        [ 'ctd_name', 'ctd_id' ],
                        [],
-                       __METHOD__
+                       __METHOD__,
+                       [ 'ORDER BY' => 'ctd_id' ]
                );
 
                foreach ( $changeTagDefs as $row ) {
@@ -150,6 +154,7 @@ class PopulateChangeTagDef extends Maintenance {
                $dbw = $this->lbFactory->getMainLB()->getConnection( DB_MASTER );
                $sleep = (int)$this->getOption( 'sleep', 10 );
                $lastId = 0;
+               $this->output( "Starting to add ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" );
                while ( true ) {
                        // Given that indexes might not be there, it's better to use replica
                        $ids = $dbr->selectFieldValues(
@@ -157,7 +162,7 @@ class PopulateChangeTagDef extends Maintenance {
                                'ct_id',
                                [ 'ct_tag' => $tagName, 'ct_tag_id' => null, 'ct_id > ' . $lastId ],
                                __METHOD__,
-                               [ 'LIMIT' => $this->getBatchSize() ]
+                               [ 'LIMIT' => $this->getBatchSize(), 'ORDER BY' => 'ct_id' ]
                        );
 
                        if ( !$ids ) {
@@ -170,6 +175,8 @@ class PopulateChangeTagDef extends Maintenance {
                                        "These ids will be changed to have \"{$tagId}\" as tag id: " . implode( ', ', $ids ) . "\n"
                                );
                                continue;
+                       } else {
+                               $this->output( "Updating ct_tag_id = {$tagId} up to row ct_id = {$lastId}\n" );
                        }
 
                        $dbw->update(
@@ -184,6 +191,8 @@ class PopulateChangeTagDef extends Maintenance {
                                sleep( $sleep );
                        }
                }
+
+               $this->output( "Finished adding ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" );
        }
 
 }