*/
class FixBug20757 extends Maintenance {
public $batchSize = 10000;
- public $mapCache = array();
+ public $mapCache = [];
public $mapCacheSize = 0;
public $maxMapCacheSize = 1000000;
function __construct() {
parent::__construct();
- $this->mDescription = 'Script to fix bug 20757 assuming that blob_tracking is intact';
+ $this->addDescription( 'Script to fix bug 20757 assuming that blob_tracking is intact' );
$this->addOption( 'dry-run', 'Report only' );
$this->addOption( 'start', 'old_id to start at', false, true );
}
function execute() {
- $dbr = wfGetDB( DB_SLAVE );
- $dbw = wfGetDB( DB_MASTER );
+ $dbr = $this->getDB( DB_SLAVE );
+ $dbw = $this->getDB( DB_MASTER );
$dryRun = $this->getOption( 'dry-run' );
if ( $dryRun ) {
$res = $dbr->select(
'text',
- array( 'old_id', 'old_flags', 'old_text' ),
- array(
+ [ 'old_id', 'old_flags', 'old_text' ],
+ [
'old_id > ' . intval( $startId ),
'old_flags LIKE \'%object%\' AND old_flags NOT LIKE \'%external%\'',
"$lowerLeft = 'o:15:\"historyblobstub\"'",
- ),
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'old_id',
'LIMIT' => $this->batchSize,
- )
+ ]
);
if ( !$res->numRows() ) {
break;
}
- $secondaryIds = array();
- $stubs = array();
+ $secondaryIds = [];
+ $stubs = [];
foreach ( $res as $row ) {
$startId = $row->old_id;
// Queue the stub for future batch processing
$id = intval( $obj->mOldId );
$secondaryIds[] = $id;
- $stubs[$row->old_id] = array(
+ $stubs[$row->old_id] = [
'legacyEncoding' => $legacyEncoding,
'secondaryId' => $id,
'hash' => $obj->mHash,
- );
+ ];
}
$secondaryIds = array_unique( $secondaryIds );
$res = $dbr->select(
'blob_tracking',
'*',
- array(
+ [
'bt_text_id' => $secondaryIds,
- ),
+ ],
__METHOD__
);
- $trackedBlobs = array();
+ $trackedBlobs = [];
foreach ( $res as $row ) {
$trackedBlobs[$row->bt_text_id] = $row;
}
// No tracked blob. Work out what went wrong
$secondaryRow = $dbr->selectRow(
'text',
- array( 'old_flags', 'old_text' ),
- array( 'old_id' => $secondaryId ),
+ [ 'old_flags', 'old_text' ],
+ [ 'old_id' => $secondaryId ],
__METHOD__
);
if ( !$secondaryRow ) {
if ( !$dryRun ) {
// Reset the text row to point to the original copy
- $dbw->begin( __METHOD__ );
+ $this->beginTransaction( $dbw, __METHOD__ );
$dbw->update(
'text',
// SET
- array(
+ [
'old_flags' => $newFlags,
'old_text' => $url
- ),
+ ],
// WHERE
- array( 'old_id' => $primaryId ),
+ [ 'old_id' => $primaryId ],
__METHOD__
);
// Add a blob_tracking row so that the new reference can be recompressed
// without needing to run trackBlobs.php again
$dbw->insert( 'blob_tracking',
- array(
+ [
'bt_page' => $pageId,
'bt_rev_id' => $revId,
'bt_text_id' => $primaryId,
'bt_cgz_hash' => $stub['hash'],
'bt_new_url' => null,
'bt_moved' => 0,
- ),
+ ],
__METHOD__
);
- $dbw->commit( __METHOD__ );
+ $this->commitTransaction( $dbw, __METHOD__ );
$this->waitForSlaves();
}
unset( $this->mapCache[$key] );
}
- $dbr = wfGetDB( DB_SLAVE );
- $map = array();
+ $dbr = $this->getDB( DB_SLAVE );
+ $map = [];
$res = $dbr->select( 'revision',
- array( 'rev_id', 'rev_text_id' ),
- array( 'rev_page' => $pageId ),
+ [ 'rev_id', 'rev_text_id' ],
+ [ 'rev_page' => $pageId ],
__METHOD__
);
foreach ( $res as $row ) {
if ( $path == "" ) {
return false;
}
- $text = ExternalStore::fetchFromUrl( $url );
+ $text = ExternalStore::fetchFromURL( $url );
}
if ( !in_array( 'object', $flags ) ) {
return false;