$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();
$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;
}
$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 ) ) {
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];
);
}
} 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] );
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] );
// 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
+ );
}
}
}
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() {
$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 );
* @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;
}
$compress = $storeObj->store( $extdb, $compress );
if ( $compress === false ) {
$this->error( "Unable to store object" );
+
return false;
}
}
), __METHOD__,
array( 'LIMIT' => 1 )
);
+
return true;
}
# 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 . "'";
if ( $endDate ) {
if ( !preg_match( '/^\d{14}$/', $endDate ) ) {
$this->error( "Invalid end date \"$endDate\"\n" );
+
return false;
}
$conds[] = "rev_timestamp<'" . $endDate . "'";
$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
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
}
$this->output( "\n" );
}
+
return true;
}
-
}
$maintClass = 'CompressOld';
$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;
}
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 ) {
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 );
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 );
}
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',
}
# 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
);
$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 );
}