Pass phpcs-strict on maintenance/storage/
authorSiebrand Mazeland <siebrand@kitano.nl>
Tue, 22 Apr 2014 20:23:18 +0000 (22:23 +0200)
committerSiebrand Mazeland <siebrand@kitano.nl>
Tue, 22 Apr 2014 20:23:18 +0000 (22:23 +0200)
Change-Id: Ia39b316e01797ddedd71885c2f05fe57ba4b89e9

maintenance/storage/checkStorage.php
maintenance/storage/compressOld.php
maintenance/storage/fixBug20757.php
maintenance/storage/orphanStats.php
maintenance/storage/recompressTracked.php
maintenance/storage/resolveStubs.php
maintenance/storage/testCompression.php

index 9174d12..6b8b5a3 100644 (file)
@@ -211,8 +211,12 @@ class CheckStorage {
                        $curIds = array();
                        if ( count( $objectRevs ) ) {
                                $headerLength = 300;
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
-                                       array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), __METHOD__ );
+                               $res = $dbr->select(
+                                       'text',
+                                       array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
+                                       array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ),
+                                       __METHOD__
+                               );
                                foreach ( $res as $row ) {
                                        $oldId = $row->old_id;
                                        $matches = array();
@@ -223,7 +227,11 @@ class CheckStorage {
 
                                        $className = strtolower( $matches[2] );
                                        if ( strlen( $className ) != $matches[1] ) {
-                                               $this->error( 'restore text', "Error: invalid object header, wrong class name length", $oldId );
+                                               $this->error(
+                                                       'restore text',
+                                                       "Error: invalid object header, wrong class name length",
+                                                       $oldId
+                                               );
                                                continue;
                                        }
 
@@ -262,8 +270,12 @@ class CheckStorage {
                        $externalConcatBlobs = array();
                        if ( count( $concatBlobs ) ) {
                                $headerLength = 300;
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
-                                       array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), __METHOD__ );
+                               $res = $dbr->select(
+                                       'text',
+                                       array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
+                                       array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ),
+                                       __METHOD__
+                               );
                                foreach ( $res as $row ) {
                                        $flags = explode( ',', $row->old_flags );
                                        if ( in_array( 'external', $flags ) ) {
@@ -271,7 +283,11 @@ class CheckStorage {
                                                if ( in_array( 'object', $flags ) ) {
                                                        $urlParts = explode( '/', $row->header );
                                                        if ( $urlParts[0] != 'DB:' ) {
-                                                               $this->error( 'unfixable', "Error: unrecognised external storage type \"{$urlParts[0]}", $row->old_id );
+                                                               $this->error(
+                                                                       'unfixable',
+                                                                       "Error: unrecognised external storage type \"{$urlParts[0]}",
+                                                                       $row->old_id
+                                                               );
                                                        } else {
                                                                $cluster = $urlParts[2];
                                                                $id = $urlParts[3];
@@ -283,12 +299,20 @@ class CheckStorage {
                                                                );
                                                        }
                                                } else {
-                                                       $this->error( 'unfixable', "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
+                                                       $this->error(
+                                                               'unfixable',
+                                                               "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
                                                                $concatBlobs[$row->old_id] );
                                                }
-                                       } elseif ( strcasecmp( substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ), self::CONCAT_HEADER ) ) {
-                                               $this->error( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}",
-                                                       $concatBlobs[$row->old_id] );
+                                       } elseif ( strcasecmp(
+                                               substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ),
+                                               self::CONCAT_HEADER
+                                       ) ) {
+                                               $this->error(
+                                                       'restore text',
+                                                       "Error: Incorrect object header for concat bulk row {$row->old_id}",
+                                                       $concatBlobs[$row->old_id]
+                                               );
                                        } # else good
 
                                        unset( $concatBlobs[$row->old_id] );
@@ -372,8 +396,11 @@ class CheckStorage {
                                array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), __METHOD__ );
                        foreach ( $res as $row ) {
                                if ( strcasecmp( $row->header, self::CONCAT_HEADER ) ) {
-                                       $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
-                                               $oldIds[$row->blob_id] );
+                                       $this->error(
+                                               'restore text',
+                                               "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
+                                               $oldIds[$row->blob_id]
+                                       );
                                }
                                unset( $oldIds[$row->blob_id] );
 
@@ -382,7 +409,11 @@ class CheckStorage {
 
                        // Print errors for missing blobs rows
                        foreach ( $oldIds as $blobId => $oldIds2 ) {
-                               $this->error( 'restore text', "Error: missing target $cluster/$blobId for two-part ES URL", $oldIds2 );
+                               $this->error(
+                                       'restore text',
+                                       "Error: missing target $cluster/$blobId for two-part ES URL",
+                                       $oldIds2
+                               );
                        }
                }
        }
index e824d8c..0f337ec 100644 (file)
@@ -59,12 +59,41 @@ class CompressOld extends Maintenance {
                parent::__construct();
                $this->mDescription = 'Compress the text of a wiki';
                $this->addOption( 'type', 'Set compression type to either: gzip|concat', false, true, 't' );
-               $this->addOption( 'chunksize', 'Maximum number of revisions in a concat chunk', false, true, 'c' );
-               $this->addOption( 'begin-date', 'Earliest date to check for uncompressed revisions', false, true, 'b' );
+               $this->addOption(
+                       'chunksize',
+                       'Maximum number of revisions in a concat chunk',
+                       false,
+                       true,
+                       'c'
+               );
+               $this->addOption(
+                       'begin-date',
+                       'Earliest date to check for uncompressed revisions',
+                       false,
+                       true,
+                       'b'
+               );
                $this->addOption( 'end-date', 'Latest revision date to compress', false, true, 'e' );
-               $this->addOption( 'startid', 'The id to start from (gzip -> text table, concat -> page table)', false, true, 's' );
-               $this->addOption( 'extdb', 'Store specified revisions in an external cluster (untested)', false, true );
-               $this->addOption( 'endid', 'The page_id to stop at (only when using concat compression type)', false, true, 'n' );
+               $this->addOption(
+                       'startid',
+                       'The id to start from (gzip -> text table, concat -> page table)',
+                       false,
+                       true,
+                       's'
+               );
+               $this->addOption(
+                       'extdb',
+                       'Store specified revisions in an external cluster (untested)',
+                       false,
+                       true
+               );
+               $this->addOption(
+                       'endid',
+                       'The page_id to stop at (only when using concat compression type)',
+                       false,
+                       true,
+                       'n'
+               );
        }
 
        public function execute() {
@@ -113,17 +142,26 @@ class CompressOld extends Maintenance {
                $this->output( "Starting from old_id $start...\n" );
                $dbw = wfGetDB( DB_MASTER );
                do {
-                       $res = $dbw->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
-                               "old_id>=$start", __METHOD__, array( 'ORDER BY' => 'old_id', 'LIMIT' => $chunksize, 'FOR UPDATE' ) );
+                       $res = $dbw->select(
+                               'text',
+                               array( 'old_id', 'old_flags', 'old_text' ),
+                               "old_id>=$start",
+                               __METHOD__,
+                               array( 'ORDER BY' => 'old_id', 'LIMIT' => $chunksize, 'FOR UPDATE' )
+                       );
+
                        if ( $res->numRows() == 0 ) {
                                break;
                        }
+
                        $last = $start;
+
                        foreach ( $res as $row ) {
                                # print "  {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
                                $this->compressPage( $row, $extdb );
                                $last = $row->old_id;
                        }
+
                        $start = $last + 1; # Deletion may leave long empty stretches
                        $this->output( "$start...\n" );
                } while ( true );
@@ -136,7 +174,9 @@ class CompressOld extends Maintenance {
         * @return bool
         */
        private function compressPage( $row, $extdb ) {
-               if ( false !== strpos( $row->old_flags, 'gzip' ) || false !== strpos( $row->old_flags, 'object' ) ) {
+               if ( false !== strpos( $row->old_flags, 'gzip' )
+                       || false !== strpos( $row->old_flags, 'object' )
+               ) {
                        #print "Already compressed row {$row->old_id}\n";
                        return false;
                }
@@ -150,6 +190,7 @@ class CompressOld extends Maintenance {
                        $compress = $storeObj->store( $extdb, $compress );
                        if ( $compress === false ) {
                                $this->error( "Unable to store object" );
+
                                return false;
                        }
                }
@@ -164,6 +205,7 @@ class CompressOld extends Maintenance {
                        ), __METHOD__,
                        array( 'LIMIT' => 1 )
                );
+
                return true;
        }
 
@@ -213,12 +255,15 @@ class CompressOld extends Maintenance {
                # overwriting bulk storage concat rows. Don't compress external references, because
                # the script doesn't yet delete rows from external storage.
                $conds = array(
-                       'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'object', $dbr->anyString() ) . ' AND old_flags NOT '
-                               . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) );
+                       'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'object', $dbr->anyString() )
+                       . ' AND old_flags NOT '
+                       . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() )
+               );
 
                if ( $beginDate ) {
                        if ( !preg_match( '/^\d{14}$/', $beginDate ) ) {
                                $this->error( "Invalid begin date \"$beginDate\"\n" );
+
                                return false;
                        }
                        $conds[] = "rev_timestamp>'" . $beginDate . "'";
@@ -226,6 +271,7 @@ class CompressOld extends Maintenance {
                if ( $endDate ) {
                        if ( !preg_match( '/^\d{14}$/', $endDate ) ) {
                                $this->error( "Invalid end date \"$endDate\"\n" );
+
                                return false;
                        }
                        $conds[] = "rev_timestamp<'" . $endDate . "'";
@@ -303,8 +349,10 @@ class CompressOld extends Maintenance {
                                $usedChunk = false;
                                $primaryOldid = $revs[$i]->rev_text_id;
 
+                               // @codingStandardsIgnoreStart Ignore avoid function calls in a FOR loop test part warning
                                # Get the text of each revision and add it to the object
                                for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy(); $j++ ) {
+                                       // @codingStandardsIgnoreEnd
                                        $oldid = $revs[$i + $j]->rev_text_id;
 
                                        # Get text
@@ -350,9 +398,10 @@ class CompressOld extends Maintenance {
                                if ( $usedChunk ) {
                                        if ( $extdb != "" ) {
                                                # Move blob objects to External Storage
-                                               $stored = $storeObj->store( $extdb, serialize( $chunk ));
+                                               $stored = $storeObj->store( $extdb, serialize( $chunk ) );
                                                if ( $stored === false ) {
                                                        $this->error( "Unable to store object" );
+
                                                        return false;
                                                }
                                                # Store External Storage URLs instead of Stub placeholders
@@ -406,9 +455,9 @@ class CompressOld extends Maintenance {
                        }
                        $this->output( "\n" );
                }
+
                return true;
        }
-
 }
 
 $maintClass = 'CompressOld';
index ff2a9ef..bfa269b 100644 (file)
@@ -311,7 +311,10 @@ class FixBug20757 extends Maintenance {
                $text = $secondaryRow->old_text;
                if ( in_array( 'external', $flags ) ) {
                        $url = $text;
-                       @list( /* $proto */ , $path ) = explode( '://', $url, 2 );
+                       wfSuppressWarnings();
+                       list( /* $proto */ , $path ) = explode( '://', $url, 2 );
+                       wfRestoreWarnings();
+
                        if ( $path == "" ) {
                                return false;
                        }
index 1df1501..9dc5280 100644 (file)
@@ -32,7 +32,8 @@ require_once __DIR__ . '/../Maintenance.php';
 class OrphanStats extends Maintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "how some statistics on the blob_orphans table, created with trackBlobs.php";
+               $this->mDescription =
+                       "Show some statistics on the blob_orphans table, created with trackBlobs.php";
        }
 
        protected function &getDB( $cluster, $groups = array(), $wiki = false ) {
@@ -54,7 +55,12 @@ class OrphanStats extends Maintenance {
 
                foreach ( $res as $boRow ) {
                        $extDB = $this->getDB( $boRow->bo_cluster );
-                       $blobRow = $extDB->selectRow( 'blobs', '*', array( 'blob_id' => $boRow->bo_blob_id ), __METHOD__ );
+                       $blobRow = $extDB->selectRow(
+                               'blobs',
+                               '*',
+                               array( 'blob_id' => $boRow->bo_blob_id ),
+                               __METHOD__
+                       );
 
                        $num++;
                        $size = strlen( $blobRow->blob_text );
index 27d9cb0..b19a0b3 100644 (file)
@@ -27,14 +27,16 @@ require __DIR__ . '/../commandLine.inc';
 
 if ( count( $args ) < 1 ) {
        echo "Usage: php recompressTracked.php [options] <cluster> [... <cluster>...]
-Moves blobs indexed by trackBlobs.php to a specified list of destination clusters, and recompresses them in the process. Restartable.
+Moves blobs indexed by trackBlobs.php to a specified list of destination clusters,
+and recompresses them in the process. Restartable.
 
 Options:
-       --procs <procs>         Set the number of child processes (default 1)
-       --copy-only             Copy only, do not update the text table. Restart without this option to complete.
-       --debug-log <file>      Log debugging data to the specified file
-       --info-log <file>       Log progress messages to the specified file
-       --critical-log <file>   Log error messages to the specified file
+       --procs <procs>       Set the number of child processes (default 1)
+       --copy-only           Copy only, do not update the text table. Restart
+                             without this option to complete.
+       --debug-log <file>    Log debugging data to the specified file
+       --info-log <file>     Log progress messages to the specified file
+       --critical-log <file> Log error messages to the specified file
 ";
        exit( 1 );
 }
@@ -63,8 +65,15 @@ class RecompressTracked {
        public $debugLog, $infoLog, $criticalLog;
        public $store;
 
-       static $optionsWithArgs = array( 'procs', 'slave-id', 'debug-log', 'info-log', 'critical-log' );
-       static $cmdLineOptionMap = array(
+       private static $optionsWithArgs = array(
+               'procs',
+               'slave-id',
+               'debug-log',
+               'info-log',
+               'critical-log'
+       );
+
+       private static $cmdLineOptionMap = array(
                'no-count' => 'noCount',
                'procs' => 'numProcs',
                'copy-only' => 'copyOnly',
index e47d640..4ac5a98 100644 (file)
@@ -81,8 +81,13 @@ function resolveStub( $id, $stubText, $flags ) {
        }
 
        # Get the (maybe) external row
-       $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
-               array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
+       $externalRow = $dbr->selectRow(
+               'text',
+               array( 'old_text' ),
+               array(
+                       'old_id' => $stub->mOldId,
+                       'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() )
+               ),
                $fname
        );
 
index d693986..f7ec662 100644 (file)
@@ -24,8 +24,9 @@
 $optionsWithArgs = array( 'start', 'limit', 'type' );
 require __DIR__ . '/../commandLine.inc';
 
-if ( !isset( $args[0] )  ) {
-       echo "Usage: php testCompression.php [--type=<type>] [--start=<start-date>] [--limit=<num-revs>] <page-title>\n";
+if ( !isset( $args[0] ) ) {
+       echo "Usage: php testCompression.php [--type=<type>] [--start=<start-date>] " .
+               "[--limit=<num-revs>] <page-title>\n";
        exit( 1 );
 }