updateCollation.php: Improve --dry-run mode
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 15 Feb 2018 17:52:26 +0000 (18:52 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 15 Feb 2018 19:39:48 +0000 (19:39 +0000)
Now prints the number of rows that would be modified after each batch.
This is meant to be useful for sysadmins who are upgrading the ICU
library on their servers and wondering whether they need to run
`updateCollation.php --force` to avoid ordering problems.

Change-Id: Ie0c37d279d4e5bc1c69408d714246625c81c70fa

maintenance/updateCollation.php

index 63176cb..54ae130 100644 (file)
@@ -200,7 +200,11 @@ TEXT
                                        $this->updateSortKeySizeHistogram( $newSortKey );
                                }
 
-                               if ( !$dryRun ) {
+                               if ( $dryRun ) {
+                                       // Add 1 to the count if the sortkey was changed. (Note that this doesn't count changes in
+                                       // other fields, if any, those usually only happen when upgrading old MediaWikis.)
+                                       $count += ( $row->cl_sortkey !== $newSortKey );
+                               } else {
                                        $dbw->update(
                                                'categorylinks',
                                                [
@@ -213,6 +217,7 @@ TEXT
                                                [ 'cl_from' => $row->cl_from, 'cl_to' => $row->cl_to ],
                                                __METHOD__
                                        );
+                                       $count++;
                                }
                                if ( $row ) {
                                        $batchConds = [ $this->getBatchCondition( $row, $dbw ) ];
@@ -222,8 +227,11 @@ TEXT
                                $this->commitTransaction( $dbw, __METHOD__ );
                        }
 
-                       $count += $res->numRows();
-                       $this->output( "$count done.\n" );
+                       if ( $dryRun ) {
+                               $this->output( "$count rows would be updated so far.\n" );
+                       } else {
+                               $this->output( "$count done.\n" );
+                       }
 
                        if ( !$dryRun && ++$batchCount % self::SYNC_INTERVAL == 0 ) {
                                $this->output( "Waiting for replica DBs ... " );
@@ -232,7 +240,9 @@ TEXT
                        }
                } while ( $res->numRows() == self::BATCH_SIZE );
 
-               $this->output( "$count rows processed\n" );
+               if ( !$dryRun ) {
+                       $this->output( "$count rows processed\n" );
+               }
 
                if ( $verboseStats ) {
                        $this->output( "\n" );