From ceafdce5f9da7f663a4a72045fb9ae69f36de290 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Tue, 22 Apr 2014 22:23:18 +0200 Subject: [PATCH 1/1] Pass phpcs-strict on maintenance/storage/ Change-Id: Ia39b316e01797ddedd71885c2f05fe57ba4b89e9 --- maintenance/storage/checkStorage.php | 57 ++++++++++++++---- maintenance/storage/compressOld.php | 73 +++++++++++++++++++---- maintenance/storage/fixBug20757.php | 5 +- maintenance/storage/orphanStats.php | 10 +++- maintenance/storage/recompressTracked.php | 25 +++++--- maintenance/storage/resolveStubs.php | 9 ++- maintenance/storage/testCompression.php | 5 +- 7 files changed, 144 insertions(+), 40 deletions(-) diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 9174d126ad..6b8b5a36fa 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -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 + ); } } } diff --git a/maintenance/storage/compressOld.php b/maintenance/storage/compressOld.php index e824d8c15a..0f337ec046 100644 --- a/maintenance/storage/compressOld.php +++ b/maintenance/storage/compressOld.php @@ -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'; diff --git a/maintenance/storage/fixBug20757.php b/maintenance/storage/fixBug20757.php index ff2a9efc3b..bfa269befd 100644 --- a/maintenance/storage/fixBug20757.php +++ b/maintenance/storage/fixBug20757.php @@ -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; } diff --git a/maintenance/storage/orphanStats.php b/maintenance/storage/orphanStats.php index 1df1501e8d..9dc5280be8 100644 --- a/maintenance/storage/orphanStats.php +++ b/maintenance/storage/orphanStats.php @@ -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 ); diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 27d9cb03d6..b19a0b31a9 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -27,14 +27,16 @@ require __DIR__ . '/../commandLine.inc'; if ( count( $args ) < 1 ) { echo "Usage: php recompressTracked.php [options] [... ...] -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 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 Log debugging data to the specified file - --info-log Log progress messages to the specified file - --critical-log Log error messages to the specified file + --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 Log debugging data to the specified file + --info-log Log progress messages to the specified file + --critical-log 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', diff --git a/maintenance/storage/resolveStubs.php b/maintenance/storage/resolveStubs.php index e47d6407e9..4ac5a98b4f 100644 --- a/maintenance/storage/resolveStubs.php +++ b/maintenance/storage/resolveStubs.php @@ -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 ); diff --git a/maintenance/storage/testCompression.php b/maintenance/storage/testCompression.php index d693986cb8..f7ec6624e6 100644 --- a/maintenance/storage/testCompression.php +++ b/maintenance/storage/testCompression.php @@ -24,8 +24,9 @@ $optionsWithArgs = array( 'start', 'limit', 'type' ); require __DIR__ . '/../commandLine.inc'; -if ( !isset( $args[0] ) ) { - echo "Usage: php testCompression.php [--type=] [--start=] [--limit=] \n"; +if ( !isset( $args[0] ) ) { + echo "Usage: php testCompression.php [--type=] [--start=] " . + "[--limit=] \n"; exit( 1 ); } -- 2.20.1