Fix maintenance script that populates the ip_changes table
authorMusikAnimal <musikanimal@gmail.com>
Tue, 5 Sep 2017 21:21:55 +0000 (17:21 -0400)
committerMusikAnimal <musikanimal@gmail.com>
Tue, 5 Sep 2017 21:22:01 +0000 (17:22 -0400)
Change-Id: Ice1bdae3d16cf365da14c6df0e8d91d2b914e065

maintenance/populateIpChanges.php

index 7a8bfc4..eb60f80 100644 (file)
@@ -67,7 +67,7 @@ TEXT
                $this->output( "Copying IP revisions to ip_changes, from rev_id $start to rev_id $end\n" );
 
                while ( $blockStart <= $end ) {
-                       $cond = "rev_id > $blockStart AND rev_user = 0 ORDER BY rev_id ASC LIMIT " . $this->mBatchSize;
+                       $cond = "rev_id >= $blockStart AND rev_user = 0 ORDER BY rev_id ASC LIMIT " . $this->mBatchSize;
                        $rows = $dbw->select(
                                'revision',
                                [ 'rev_id', 'rev_timestamp', 'rev_user_text' ],
@@ -79,27 +79,27 @@ TEXT
                                break;
                        }
 
-                       $this->output( "...copying $this->mBatchSize revisions starting with rev_id $blockStart\n" );
+                       $this->output( "...checking $this->mBatchSize revisions for IP edits that need copying, " .
+                               "starting with rev_id $blockStart\n" );
 
                        foreach ( $rows as $row ) {
                                // Double-check to make sure this is an IP, e.g. not maintenance user or imported revision.
-                               if ( !IP::isValid( $row->rev_user_text ) ) {
-                                       continue;
+                               if ( IP::isValid( $row->rev_user_text ) ) {
+                                       $dbw->insert(
+                                               'ip_changes',
+                                               [
+                                                       'ipc_rev_id' => $row->rev_id,
+                                                       'ipc_rev_timestamp' => $row->rev_timestamp,
+                                                       'ipc_hex' => IP::toHex( $row->rev_user_text ),
+                                               ],
+                                               __METHOD__,
+                                               'IGNORE'
+                                       );
+
+                                       $revCount++;
                                }
 
-                               $dbw->insert(
-                                       'ip_changes',
-                                       [
-                                               'ipc_rev_id' => $row->rev_id,
-                                               'ipc_rev_timestamp' => $row->rev_timestamp,
-                                               'ipc_hex' => IP::toHex( $row->rev_user_text ),
-                                       ],
-                                       __METHOD__,
-                                       'IGNORE'
-                               );
-
                                $blockStart = (int)$row->rev_id;
-                               $revCount++;
                        }
 
                        $blockStart++;