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 $dbw =& wfGetDB( DB_MASTER
);
23 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
25 $numBlocks = intval( $maxID / $blockSize ) +
1;
27 for ( $b = 0; $b < $numBlocks; $b++
) {
30 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
31 $start = intval($maxID / $numBlocks) * $b +
1;
32 $end = intval($maxID / $numBlocks) * ($b +
1);
34 $flagsArray = array();
37 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
38 "old_id>=$start AND old_id<=$end " .
39 # Using a more restrictive flag set for now, until I do some more analysis -- TS
40 #"AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
42 "AND old_flags='object' " .
43 "AND old_text LIKE 'O:15:\"historyblobstub\"%'", $fname );
44 while ( $row = $dbr->fetchObject( $res ) ) {
45 resolveStub( $row->old_id
, $row->old_text
, $row->old_flags
);
47 $dbr->freeResult( $res );
55 * Resolve a history stub
57 function resolveStub( $id, $stubText, $flags ) {
58 $fname = 'resolveStub';
60 $stub = unserialize( $stubText );
61 $flags = explode( ',', $flags );
63 $dbr =& wfGetDB( DB_SLAVE
);
64 $dbw =& wfGetDB( DB_MASTER
);
66 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
67 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
71 # Get the (maybe) external row
72 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
73 array( 'old_id' => $stub->mOldId
, "old_flags LIKE '%external%'" ),
77 if ( !$externalRow ) {
78 # Object wasn't external
82 # Preserve the legacy encoding flag, but switch from object to external
83 if ( in_array( 'utf-8', $flags ) ) {
84 $newFlags = 'external,utf-8';
86 $newFlags = 'external';
92 'old_flags' => $newFlags,
93 'old_text' => $externalRow->old_text
. '/' . $stub->mHash