public $orphanBatchSize = 1000;
public $reportingInterval = 10;
public $numProcs = 1;
+ public $numBatches = 0;
public $useDiff, $pageBlobClass, $orphanBlobClass;
public $slavePipes, $slaveProcs, $prevSlaveId;
public $copyOnly = false;
public $debugLog, $infoLog, $criticalLog;
public $store;
- private static $optionsWithArgs = array(
+ private static $optionsWithArgs = [
'procs',
'slave-id',
'debug-log',
'info-log',
'critical-log'
- );
+ ];
- private static $cmdLineOptionMap = array(
+ private static $cmdLineOptionMap = [
'no-count' => 'noCount',
'procs' => 'numProcs',
'copy-only' => 'copyOnly',
'debug-log' => 'debugLog',
'info-log' => 'infoLog',
'critical-log' => 'criticalLog',
- );
+ ];
static function getOptionsWithArgs() {
return self::$optionsWithArgs;
}
static function newFromCommandLine( $args, $options ) {
- $jobOptions = array( 'destClusters' => $args );
+ $jobOptions = [ 'destClusters' => $args ];
foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
if ( isset( $options[$cmdOption] ) ) {
$jobOptions[$classOption] = $options[$cmdOption];
return false;
}
- $row = $dbr->selectRow( 'blob_tracking', '*', false, __METHOD__ );
+ $row = $dbr->selectRow( 'blob_tracking', '*', '', __METHOD__ );
if ( !$row ) {
$this->info( "Warning: blob_tracking table contains no rows, skipping this wiki." );
' --wiki ' . wfEscapeShellArg( wfWikiID() ) .
' ' . call_user_func_array( 'wfEscapeShellArg', $this->destClusters );
- $this->slavePipes = $this->slaveProcs = array();
+ $this->slavePipes = $this->slaveProcs = [];
for ( $i = 0; $i < $this->numProcs; $i++ ) {
- $pipes = false;
- $spec = array(
- array( 'pipe', 'r' ),
- array( 'file', 'php://stdout', 'w' ),
- array( 'file', 'php://stderr', 'w' )
- );
+ $pipes = [];
+ $spec = [
+ [ 'pipe', 'r' ],
+ [ 'file', 'php://stdout', 'w' ],
+ [ 'file', 'php://stderr', 'w' ]
+ ];
MediaWiki\suppressWarnings();
$proc = proc_open( "$cmd --slave-id $i", $spec, $pipes );
MediaWiki\restoreWarnings();
function dispatch( /*...*/ ) {
$args = func_get_args();
$pipes = $this->slavePipes;
- $numPipes = stream_select( $x = array(), $pipes, $y = array(), 3600 );
+ $numPipes = stream_select( $x = [], $pipes, $y = [], 3600 );
if ( !$numPipes ) {
$this->critical( "Error waiting to write to slaves. Aborting" );
exit( 1 );
$numPages = $dbr->selectField( 'blob_tracking',
'COUNT(DISTINCT bt_page)',
# A condition is required so that this query uses the index
- array( 'bt_moved' => 0 ),
+ [ 'bt_moved' => 0 ],
__METHOD__
);
}
}
while ( true ) {
$res = $dbr->select( 'blob_tracking',
- array( 'bt_page' ),
- array(
+ [ 'bt_page' ],
+ [
'bt_moved' => 0,
'bt_page > ' . $dbr->addQuotes( $startId )
- ),
+ ],
__METHOD__,
- array(
+ [
'DISTINCT',
'ORDER BY' => 'bt_page',
'LIMIT' => $this->batchSize,
- )
+ ]
);
if ( !$res->numRows() ) {
break;
}
foreach ( $res as $row ) {
+ $startId = $row->bt_page;
$this->dispatch( 'doPage', $row->bt_page );
$i++;
}
- $startId = $row->bt_page;
$this->report( 'pages', $i, $numPages );
}
$this->report( 'pages', $i, $numPages );
} else {
$numOrphans = $dbr->selectField( 'blob_tracking',
'COUNT(DISTINCT bt_text_id)',
- array( 'bt_moved' => 0, 'bt_page' => 0 ),
+ [ 'bt_moved' => 0, 'bt_page' => 0 ],
__METHOD__ );
if ( !$numOrphans ) {
return;
while ( true ) {
$res = $dbr->select( 'blob_tracking',
- array( 'bt_text_id' ),
- array(
+ [ 'bt_text_id' ],
+ [
'bt_moved' => 0,
'bt_page' => 0,
'bt_text_id > ' . $dbr->addQuotes( $startId )
- ),
+ ],
__METHOD__,
- array(
+ [
'DISTINCT',
'ORDER BY' => 'bt_text_id',
'LIMIT' => $this->batchSize
- )
+ ]
);
if ( !$res->numRows() ) {
break;
}
- $ids = array();
+ $ids = [];
foreach ( $res as $row ) {
+ $startId = $row->bt_text_id;
$ids[] = $row->bt_text_id;
$i++;
}
$args = array_slice( $ids, 0, $this->orphanBatchSize );
$ids = array_slice( $ids, $this->orphanBatchSize );
array_unshift( $args, 'doOrphanList' );
- call_user_func_array( array( $this, 'dispatch' ), $args );
+ call_user_func_array( [ $this, 'dispatch' ], $args );
}
if ( count( $ids ) ) {
$args = $ids;
array_unshift( $args, 'doOrphanList' );
- call_user_func_array( array( $this, 'dispatch' ), $args );
+ call_user_func_array( [ $this, 'dispatch' ], $args );
}
- $startId = $row->bt_text_id;
$this->report( 'orphans', $i, $numOrphans );
}
$this->report( 'orphans', $i, $numOrphans );
// Finish any incomplete transactions
if ( !$this->copyOnly ) {
- $this->finishIncompleteMoves( array( 'bt_page' => $pageId ) );
+ $this->finishIncompleteMoves( [ 'bt_page' => $pageId ] );
$this->syncDBs();
}
while ( true ) {
$res = $dbr->select(
- array( 'blob_tracking', 'text' ),
+ [ 'blob_tracking', 'text' ],
'*',
- array(
+ [
'bt_page' => $pageId,
'bt_text_id > ' . $dbr->addQuotes( $startId ),
'bt_moved' => 0,
'bt_new_url IS NULL',
'bt_text_id=old_id',
- ),
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'bt_text_id',
'LIMIT' => $this->batchSize
- )
+ ]
);
if ( !$res->numRows() ) {
break;
$lastTextId = 0;
foreach ( $res as $row ) {
+ $startId = $row->bt_text_id;
if ( $lastTextId == $row->bt_text_id ) {
// Duplicate (null edit)
continue;
wfWaitForSlaves();
}
}
- $startId = $row->bt_text_id;
}
$this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" );
$dbw = wfGetDB( DB_MASTER );
$dbw->begin( __METHOD__ );
$dbw->update( 'text',
- array( // set
+ [ // set
'old_text' => $url,
'old_flags' => 'external,utf-8',
- ),
- array( // where
+ ],
+ [ // where
'old_id' => $textId
- ),
+ ],
__METHOD__
);
$dbw->update( 'blob_tracking',
- array( 'bt_moved' => 1 ),
- array( 'bt_text_id' => $textId ),
+ [ 'bt_moved' => 1 ],
+ [ 'bt_text_id' => $textId ],
__METHOD__
);
$dbw->commit( __METHOD__ );
$dbr = wfGetDB( DB_SLAVE );
$startId = 0;
- $conds = array_merge( $conds, array(
+ $conds = array_merge( $conds, [
'bt_moved' => 0,
'bt_new_url IS NOT NULL'
- ) );
+ ] );
while ( true ) {
$res = $dbr->select( 'blob_tracking',
'*',
- array_merge( $conds, array( 'bt_text_id > ' . $dbr->addQuotes( $startId ) ) ),
+ array_merge( $conds, [ 'bt_text_id > ' . $dbr->addQuotes( $startId ) ] ),
__METHOD__,
- array(
+ [
'ORDER BY' => 'bt_text_id',
'LIMIT' => $this->batchSize,
- )
+ ]
);
if ( !$res->numRows() ) {
break;
}
$this->debug( 'Incomplete: ' . $res->numRows() . ' rows' );
foreach ( $res as $row ) {
+ $startId = $row->bt_text_id;
$this->moveTextRow( $row->bt_text_id, $row->bt_new_url );
if ( $row->bt_text_id % 10 == 0 ) {
wfWaitForSlaves();
}
}
- $startId = $row->bt_text_id;
}
}
function doOrphanList( $textIds ) {
// Finish incomplete moves
if ( !$this->copyOnly ) {
- $this->finishIncompleteMoves( array( 'bt_text_id' => $textIds ) );
+ $this->finishIncompleteMoves( [ 'bt_text_id' => $textIds ] );
$this->syncDBs();
}
$trx = new CgzCopyTransaction( $this, $this->orphanBlobClass );
$res = wfGetDB( DB_SLAVE )->select(
- array( 'text', 'blob_tracking' ),
- array( 'old_id', 'old_text', 'old_flags' ),
- array(
+ [ 'text', 'blob_tracking' ],
+ [ 'old_id', 'old_text', 'old_flags' ],
+ [
'old_id' => $textIds,
'bt_text_id=old_id',
'bt_moved' => 0,
- ),
+ ],
__METHOD__,
- array( 'DISTINCT' )
+ [ 'DISTINCT' ]
);
foreach ( $res as $row ) {
* Class to represent a recompression operation for a single CGZ blob
*/
class CgzCopyTransaction {
+ /** @var RecompressTracked */
public $parent;
public $blobClass;
+ /** @var ConcatenatedGzipHistoryBlob */
public $cgz;
public $referrers;
function __construct( $parent, $blobClass ) {
$this->blobClass = $blobClass;
$this->cgz = false;
- $this->texts = array();
+ $this->texts = [];
$this->parent = $parent;
}
function recompress() {
$class = $this->blobClass;
$this->cgz = new $class;
- $this->referrers = array();
+ $this->referrers = [];
foreach ( $this->texts as $textId => $text ) {
$hash = $this->cgz->addItem( $text );
$this->referrers[$textId] = $hash;
return;
}
- // Check to see if the target text_ids have been moved already.
- //
- // We originally read from the slave, so this can happen when a single
- // text_id is shared between multiple pages. It's rare, but possible
- // if a delete/move/undelete cycle splits up a null edit.
- //
- // We do a locking read to prevent closer-run race conditions.
+ /* Check to see if the target text_ids have been moved already.
+ *
+ * We originally read from the slave, so this can happen when a single
+ * text_id is shared between multiple pages. It's rare, but possible
+ * if a delete/move/undelete cycle splits up a null edit.
+ *
+ * We do a locking read to prevent closer-run race conditions.
+ */
$dbw = wfGetDB( DB_MASTER );
$dbw->begin( __METHOD__ );
$res = $dbw->select( 'blob_tracking',
- array( 'bt_text_id', 'bt_moved' ),
- array( 'bt_text_id' => array_keys( $this->referrers ) ),
- __METHOD__, array( 'FOR UPDATE' ) );
+ [ 'bt_text_id', 'bt_moved' ],
+ [ 'bt_text_id' => array_keys( $this->referrers ) ],
+ __METHOD__, [ 'FOR UPDATE' ] );
$dirty = false;
foreach ( $res as $row ) {
if ( $row->bt_moved ) {
// All have been moved already
if ( $originalCount > 1 ) {
// This is suspcious, make noise
- $this->critical( "Warning: concurrent operation detected, are there two conflicting " .
+ $this->parent->critical(
+ "Warning: concurrent operation detected, are there two conflicting " .
"processes running, doing the same job?" );
}
foreach ( $this->referrers as $textId => $hash ) {
$url = $baseUrl . '/' . $hash;
$dbw->update( 'blob_tracking',
- array( 'bt_new_url' => $url ),
- array(
+ [ 'bt_new_url' => $url ],
+ [
'bt_text_id' => $textId,
'bt_moved' => 0, # Check for concurrent conflicting update
- ),
+ ],
__METHOD__
);
}