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 $dbr = wfGetDB( DB_SLAVE
);
22 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
24 $numBlocks = intval( $maxID / $blockSize ) +
1;
26 for ( $b = 0; $b < $numBlocks; $b++
) {
29 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
30 $start = intval($maxID / $numBlocks) * $b +
1;
31 $end = intval($maxID / $numBlocks) * ($b +
1);
33 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
34 "old_id>=$start AND old_id<=$end " .
35 # Using a more restrictive flag set for now, until I do some more analysis -- TS
36 #"AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
38 "AND old_flags='object' " .
39 "AND LOWER(LEFT(old_text,22)) = 'O:15:\"historyblobstub\"'", $fname );
40 while ( $row = $dbr->fetchObject( $res ) ) {
41 resolveStub( $row->old_id
, $row->old_text
, $row->old_flags
);
43 $dbr->freeResult( $res );
51 * Resolve a history stub
53 function resolveStub( $id, $stubText, $flags ) {
54 $fname = 'resolveStub';
56 $stub = unserialize( $stubText );
57 $flags = explode( ',', $flags );
59 $dbr = wfGetDB( DB_SLAVE
);
60 $dbw = wfGetDB( DB_MASTER
);
62 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
63 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
67 # Get the (maybe) external row
68 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
69 array( 'old_id' => $stub->mOldId
, "old_flags LIKE '%external%'" ),
73 if ( !$externalRow ) {
74 # Object wasn't external
78 # Preserve the legacy encoding flag, but switch from object to external
79 if ( in_array( 'utf-8', $flags ) ) {
80 $newFlags = 'external,utf-8';
82 $newFlags = 'external';
89 'old_flags' => $newFlags,
90 'old_text' => $externalRow->old_text
. '/' . $stub->mHash