00001 <?php
00007 define( 'REPORTING_INTERVAL', 100 );
00008
00009 if ( !defined( 'MEDIAWIKI' ) ) {
00010 $optionsWithArgs = array( 'm' );
00011
00012 require_once( dirname(__FILE__) . '/../commandLine.inc' );
00013
00014 resolveStubs();
00015 }
00016
00021 function resolveStubs() {
00022 $fname = 'resolveStubs';
00023
00024 $dbr = wfGetDB( DB_SLAVE );
00025 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
00026 $blockSize = 10000;
00027 $numBlocks = intval( $maxID / $blockSize ) + 1;
00028
00029 for ( $b = 0; $b < $numBlocks; $b++ ) {
00030 wfWaitForSlaves( 2 );
00031
00032 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
00033 $start = intval($maxID / $numBlocks) * $b + 1;
00034 $end = intval($maxID / $numBlocks) * ($b + 1);
00035
00036 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
00037 "old_id>=$start AND old_id<=$end " .
00038 # Using a more restrictive flag set for now, until I do some more analysis -- TS
00039 #"AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
00040
00041 "AND old_flags='object' " .
00042 "AND LOWER(LEFT(old_text,22)) = 'O:15:\"historyblobstub\"'", $fname );
00043 while ( $row = $dbr->fetchObject( $res ) ) {
00044 resolveStub( $row->old_id, $row->old_text, $row->old_flags );
00045 }
00046 $dbr->freeResult( $res );
00047
00048
00049 }
00050 print "100%\n";
00051 }
00052
00056 function resolveStub( $id, $stubText, $flags ) {
00057 $fname = 'resolveStub';
00058
00059 $stub = unserialize( $stubText );
00060 $flags = explode( ',', $flags );
00061
00062 $dbr = wfGetDB( DB_SLAVE );
00063 $dbw = wfGetDB( DB_MASTER );
00064
00065 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
00066 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
00067 return;
00068 }
00069
00070 # Get the (maybe) external row
00071 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
00072 array( 'old_id' => $stub->mOldId, "old_flags LIKE '%external%'" ),
00073 $fname
00074 );
00075
00076 if ( !$externalRow ) {
00077 # Object wasn't external
00078 return;
00079 }
00080
00081 # Preserve the legacy encoding flag, but switch from object to external
00082 if ( in_array( 'utf-8', $flags ) ) {
00083 $newFlags = 'external,utf-8';
00084 } else {
00085 $newFlags = 'external';
00086 }
00087
00088 # Update the row
00089 #print "oldid=$id\n";
00090 $dbw->update( 'text',
00091 array(
00092 'old_flags' => $newFlags,
00093 'old_text' => $externalRow->old_text . '/' . $stub->mHash
00094 ),
00095 array(
00096 'old_id' => $id
00097 ), $fname
00098 );
00099 }
00100