* Fixed some doxygen warnings
[mediawiki.git] / maintenance / storage / resolveStubs.php
blobcd8ef345504f4399c20c077c58086b7cabd408bc
1 <?php
2 /**
3 * @file
4 * @ingroup Maintenance ExternalStorage
5 */
7 define( 'REPORTING_INTERVAL', 100 );
9 if ( !defined( 'MEDIAWIKI' ) ) {
10 $optionsWithArgs = array( 'm' );
12 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
14 resolveStubs();
17 /**
18 * Convert history stubs that point to an external row to direct
19 * external pointers
21 function resolveStubs() {
22 $fname = 'resolveStubs';
24 $dbr = wfGetDB( DB_SLAVE );
25 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
26 $blockSize = 10000;
27 $numBlocks = intval( $maxID / $blockSize ) + 1;
29 for ( $b = 0; $b < $numBlocks; $b++ ) {
30 wfWaitForSlaves( 2 );
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"\'',
40 $fname );
41 foreach ( $res as $row ) {
42 resolveStub( $row->old_id, $row->old_text, $row->old_flags );
45 print "100%\n";
48 /**
49 * Resolve a history stub
51 function resolveStub( $id, $stubText, $flags ) {
52 $fname = 'resolveStub';
54 $stub = unserialize( $stubText );
55 $flags = explode( ',', $flags );
57 $dbr = wfGetDB( DB_SLAVE );
58 $dbw = wfGetDB( DB_MASTER );
60 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
61 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
62 return;
65 # Get the (maybe) external row
66 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
67 array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
68 $fname
71 if ( !$externalRow ) {
72 # Object wasn't external
73 return;
76 # Preserve the legacy encoding flag, but switch from object to external
77 if ( in_array( 'utf-8', $flags ) ) {
78 $newFlags = 'external,utf-8';
79 } else {
80 $newFlags = 'external';
83 # Update the row
84 # print "oldid=$id\n";
85 $dbw->update( 'text',
86 array( /* SET */
87 'old_flags' => $newFlags,
88 'old_text' => $externalRow->old_text . '/' . $stub->mHash
90 array( /* WHERE */
91 'old_id' => $id
92 ), $fname