b32c72f479504c051057651f9f1f4aa31908dd53
4 * @ingroup Maintenance ExternalStorage
7 define( 'REPORTING_INTERVAL', 100 );
9 if ( !defined( 'MEDIAWIKI' ) ) {
10 $optionsWithArgs = array( 'm' );
12 require_once( dirname( __FILE__
) . '/../commandLine.inc' );
18 * Convert history stubs that point to an external row to direct
21 function resolveStubs() {
22 $fname = 'resolveStubs';
24 $dbr = wfGetDB( DB_SLAVE
);
25 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
27 $numBlocks = intval( $maxID / $blockSize ) +
1;
29 for ( $b = 0; $b < $numBlocks; $b++
) {
32 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
33 $start = intval( $maxID / $numBlocks ) * $b +
1;
34 $end = intval( $maxID / $numBlocks ) * ( $b +
1 );
36 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
37 "old_id>=$start AND old_id<=$end " .
38 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
39 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
41 while ( $row = $dbr->fetchObject( $res ) ) {
42 resolveStub( $row->old_id
, $row->old_text
, $row->old_flags
);
44 $dbr->freeResult( $res );
52 * Resolve a history stub
54 function resolveStub( $id, $stubText, $flags ) {
55 $fname = 'resolveStub';
57 $stub = unserialize( $stubText );
58 $flags = explode( ',', $flags );
60 $dbr = wfGetDB( DB_SLAVE
);
61 $dbw = wfGetDB( DB_MASTER
);
63 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
64 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
68 # Get the (maybe) external row
69 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
70 array( 'old_id' => $stub->mOldId
, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
74 if ( !$externalRow ) {
75 # Object wasn't external
79 # Preserve the legacy encoding flag, but switch from object to external
80 if ( in_array( 'utf-8', $flags ) ) {
81 $newFlags = 'external,utf-8';
83 $newFlags = 'external';
87 # print "oldid=$id\n";
90 'old_flags' => $newFlags,
91 'old_text' => $externalRow->old_text
. '/' . $stub->mHash