5dfaa598b1306b970f1748dfca4ad2fa9af7c531
3 define( 'REPORTING_INTERVAL', 100 );
5 if ( !defined( 'MEDIAWIKI' ) ) {
6 $optionsWithArgs = array( 'm' );
8 require_once( dirname(__FILE__
) . '/../commandLine.inc' );
14 * Convert history stubs that point to an external row to direct
17 function resolveStubs() {
18 $fname = 'resolveStubs';
20 $dbr = wfGetDB( DB_SLAVE
);
21 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
23 $numBlocks = intval( $maxID / $blockSize ) +
1;
25 for ( $b = 0; $b < $numBlocks; $b++
) {
28 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
29 $start = intval($maxID / $numBlocks) * $b +
1;
30 $end = intval($maxID / $numBlocks) * ($b +
1);
32 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
33 "old_id>=$start AND old_id<=$end " .
34 # Using a more restrictive flag set for now, until I do some more analysis -- TS
35 #"AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
37 "AND old_flags='object' " .
38 "AND LOWER(LEFT(old_text,22)) = 'O:15:\"historyblobstub\"'", $fname );
39 while ( $row = $dbr->fetchObject( $res ) ) {
40 resolveStub( $row->old_id
, $row->old_text
, $row->old_flags
);
42 $dbr->freeResult( $res );
50 * Resolve a history stub
52 function resolveStub( $id, $stubText, $flags ) {
53 $fname = 'resolveStub';
55 $stub = unserialize( $stubText );
56 $flags = explode( ',', $flags );
58 $dbr = wfGetDB( DB_SLAVE
);
59 $dbw = wfGetDB( DB_MASTER
);
61 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
62 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
66 # Get the (maybe) external row
67 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
68 array( 'old_id' => $stub->mOldId
, "old_flags LIKE '%external%'" ),
72 if ( !$externalRow ) {
73 # Object wasn't external
77 # Preserve the legacy encoding flag, but switch from object to external
78 if ( in_array( 'utf-8', $flags ) ) {
79 $newFlags = 'external,utf-8';
81 $newFlags = 'external';
88 'old_flags' => $newFlags,
89 'old_text' => $externalRow->old_text
. '/' . $stub->mHash