Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / maintenance / cleanupBlocks.php
index f489333..cbf0084 100644 (file)
@@ -39,12 +39,14 @@ class CleanupBlocks extends Maintenance {
 
        public function execute() {
                $db = $this->getDB( DB_MASTER );
+               $blockQuery = Block::getQueryInfo();
 
                $max = $db->selectField( 'ipblocks', 'MAX(ipb_user)' );
 
                // Step 1: Clean up any duplicate user blocks
-               for ( $from = 1; $from <= $max; $from += $this->mBatchSize ) {
-                       $to = min( $max, $from + $this->mBatchSize - 1 );
+               $batchSize = $this->getBatchSize();
+               for ( $from = 1; $from <= $max; $from += $batchSize ) {
+                       $to = min( $max, $from + $batchSize - 1 );
                        $this->output( "Cleaning up duplicate ipb_user ($from-$to of $max)\n" );
 
                        $delete = [];
@@ -53,8 +55,8 @@ class CleanupBlocks extends Maintenance {
                                'ipblocks',
                                [ 'ipb_user' ],
                                [
-                                       "ipb_user >= $from",
-                                       "ipb_user <= $to",
+                                       "ipb_user >= " . (int)$from,
+                                       "ipb_user <= " . (int)$to,
                                ],
                                __METHOD__,
                                [
@@ -65,11 +67,14 @@ class CleanupBlocks extends Maintenance {
                        foreach ( $res as $row ) {
                                $bestBlock = null;
                                $res2 = $db->select(
-                                       'ipblocks',
-                                       Block::selectFields(),
+                                       $blockQuery['tables'],
+                                       $blockQuery['fields'],
                                        [
                                                'ipb_user' => $row->ipb_user,
-                                       ]
+                                       ],
+                                       __METHOD__,
+                                       [],
+                                       $blockQuery['joins']
                                );
                                foreach ( $res2 as $row2 ) {
                                        $block = Block::newFromRow( $row2 );
@@ -114,8 +119,8 @@ class CleanupBlocks extends Maintenance {
                }
 
                // Step 2: Update the user name in any blocks where it doesn't match
-               for ( $from = 1; $from <= $max; $from += $this->mBatchSize ) {
-                       $to = min( $max, $from + $this->mBatchSize - 1 );
+               for ( $from = 1; $from <= $max; $from += $batchSize ) {
+                       $to = min( $max, $from + $batchSize - 1 );
                        $this->output( "Cleaning up mismatched user name ($from-$to of $max)\n" );
 
                        $res = $db->select(
@@ -123,8 +128,8 @@ class CleanupBlocks extends Maintenance {
                                [ 'ipb_id', 'user_name' ],
                                [
                                        'ipb_user = user_id',
-                                       "ipb_user >= $from",
-                                       "ipb_user <= $to",
+                                       "ipb_user >= " . (int)$from,
+                                       "ipb_user <= " . (int)$to,
                                        'ipb_address != user_name',
                                ],
                                __METHOD__
@@ -143,5 +148,5 @@ class CleanupBlocks extends Maintenance {
        }
 }
 
-$maintClass = "CleanupBlocks";
+$maintClass = CleanupBlocks::class;
 require_once RUN_MAINTENANCE_IF_MAIN;