583341848f7b4ca098ee4c481f4013b879532f5b
3 define( 'REPORTING_INTERVAL', 100 );
5 if ( !defined( 'MEDIAWIKI' ) ) {
6 $optionsWithArgs = array( 'm' );
8 require_once( '../commandLine.inc' );
9 require_once( 'includes/ExternalStoreDB.php' );
15 * Convert history stubs that point to an external row to direct
18 function resolveStubs() {
19 $fname = 'resolveStubs';
21 print "Retrieving stub rows...\n";
22 $dbr =& wfGetDB( DB_SLAVE
);
23 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
25 $flagsArray = array();
28 for ( $b = 0; $b < 100; $b++
) {
30 $start = intval($maxID / 100) * $b +
1;
31 $end = intval($maxID / 100) * ($b +
1);
33 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
34 "old_id>=$start AND old_id<=$end AND old_flags like '%object%' ".
35 "AND old_text LIKE 'O:15:\"historyblobstub\"%'", $fname );
36 while ( $row = $dbr->fetchObject( $res ) ) {
37 $stubs[$row->old_id
] = $row->old_text
;
38 $flagsArray[$row->old_id
] = $row->old_flags
;
40 $dbr->freeResult( $res );
44 print "\nConverting " . count( $stubs ) . " rows ...\n";
46 # Get master database, no transactions
47 $dbw =& wfGetDB( DB_MASTER
);
48 $dbw->clearFlag( DBO_TRX
);
49 $dbw->immediateCommit();
52 foreach( $stubs as $id => $stub ) {
53 if ( !(++
$i % REPORTING_INTERVAL
) ) {
58 resolveStub( $id, $stub, $flagsArray[$id] );
63 * Resolve a history stub
65 function resolveStub( $id, $stubText, $flags ) {
66 $fname = 'resolveStub';
68 $stub = unserialize( $stubText );
69 $flags = explode( ',', $flags );
71 $dbr =& wfGetDB( DB_SLAVE
);
72 $dbw =& wfGetDB( DB_MASTER
);
74 if ( get_class( $stub ) !== 'historyblobstub' ) {
75 print "Error, invalid stub object\n";
79 # Get the (maybe) external row
80 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
81 array( 'old_id' => $stub->mOldId
, "old_flags LIKE '%external%'" ),
85 if ( !$externalRow ) {
86 # Object wasn't external
90 # Preserve the legacy encoding flag, but switch from object to external
91 if ( in_array( 'utf-8', $flags ) ) {
92 $newFlags = 'external,utf-8';
94 $newFlags = 'external';
100 'old_flags' => $newFlags,
101 'old_text' => $externalRow->old_text
. '/' . $stub->mHash