X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FcompressOld.php;h=0f337ec046ad223e0d2629796dc476044da86b30;hb=422300936d7bd030f2bdbeebb77fc49f681400dd;hp=3b59f1dfdb604147f26f04cc0c155fbc5d5c1abb;hpb=665f171a18061aacd339102a21f32d714c5de50d;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/compressOld.php b/maintenance/storage/compressOld.php index 3b59f1dfdb..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 ); @@ -131,12 +169,14 @@ class CompressOld extends Maintenance { /** * @todo document - * @param $row - * @param $extdb + * @param stdClass $row + * @param string $extdb * @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,16 +205,17 @@ class CompressOld extends Maintenance { ), __METHOD__, array( 'LIMIT' => 1 ) ); + return true; } /** - * @param $startId - * @param $maxChunkSize - * @param $beginDate - * @param $endDate - * @param $extdb string - * @param $maxPageId bool|int + * @param int $startId + * @param int $maxChunkSize + * @param string $beginDate + * @param string $endDate + * @param string $extdb + * @param bool|int $maxPageId * @return bool */ private function compressWithConcat( $startId, $maxChunkSize, $beginDate, @@ -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';