]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/storage/resolveStubs.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / maintenance / storage / resolveStubs.php
1 <?php
2 /**
3  * @file
4  * @ingroup Maintenance ExternalStorage
5  */
6
7 define( 'REPORTING_INTERVAL', 100 );
8
9 if ( !defined( 'MEDIAWIKI' ) ) {
10         $optionsWithArgs = array( 'm' );
11
12         require_once( dirname(__FILE__) . '/../commandLine.inc' );
13
14         resolveStubs();
15 }
16
17 /**
18  * Convert history stubs that point to an external row to direct
19  * external pointers
20  */
21 function resolveStubs() {
22         $fname = 'resolveStubs';
23
24         $dbr = wfGetDB( DB_SLAVE );
25         $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
26         $blockSize = 10000;
27         $numBlocks = intval( $maxID / $blockSize ) + 1;
28
29         for ( $b = 0; $b < $numBlocks; $b++ ) {
30                 wfWaitForSlaves( 2 );
31                 
32                 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
33                 $start = intval($maxID / $numBlocks) * $b + 1;
34                 $end = intval($maxID / $numBlocks) * ($b + 1);
35                 
36                 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
37                         "old_id>=$start AND old_id<=$end " .
38                         # Using a more restrictive flag set for now, until I do some more analysis -- TS
39                         #"AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
40                         
41                         "AND old_flags='object' " .
42                         "AND LOWER(LEFT(old_text,22)) = 'O:15:\"historyblobstub\"'", $fname );
43                 while ( $row = $dbr->fetchObject( $res ) ) {
44                         resolveStub( $row->old_id, $row->old_text, $row->old_flags );
45                 }
46                 $dbr->freeResult( $res );
47
48                 
49         }
50         print "100%\n";
51 }
52
53 /**
54  * Resolve a history stub
55  */
56 function resolveStub( $id, $stubText, $flags ) {
57         $fname = 'resolveStub';
58
59         $stub = unserialize( $stubText );
60         $flags = explode( ',', $flags );
61
62         $dbr = wfGetDB( DB_SLAVE );
63         $dbw = wfGetDB( DB_MASTER );
64
65         if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
66                 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
67                 return;
68         }
69
70         # Get the (maybe) external row
71         $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
72                 array( 'old_id' => $stub->mOldId, "old_flags LIKE '%external%'" ),
73                 $fname
74         );
75
76         if ( !$externalRow ) {
77                 # Object wasn't external
78                 return;
79         }
80
81         # Preserve the legacy encoding flag, but switch from object to external
82         if ( in_array( 'utf-8', $flags ) ) {
83                 $newFlags = 'external,utf-8';
84         } else {
85                 $newFlags = 'external';
86         }
87
88         # Update the row
89         #print "oldid=$id\n";
90         $dbw->update( 'text',
91                 array( /* SET */
92                         'old_flags' => $newFlags,
93                         'old_text' => $externalRow->old_text . '/' . $stub->mHash
94                 ),
95                 array( /* WHERE */
96                         'old_id' => $id
97                 ), $fname
98         );
99 }
100