3 * Convert history stubs that point to an external row to direct external
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup Maintenance ExternalStorage
25 define( 'REPORTING_INTERVAL', 100 );
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 $optionsWithArgs = array( 'm' );
30 require_once( __DIR__
. '/../commandLine.inc' );
36 * Convert history stubs that point to an external row to direct
39 function resolveStubs() {
40 $fname = 'resolveStubs';
42 $dbr = wfGetDB( DB_SLAVE
);
43 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
45 $numBlocks = intval( $maxID / $blockSize ) +
1;
47 for ( $b = 0; $b < $numBlocks; $b++
) {
50 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
51 $start = intval( $maxID / $numBlocks ) * $b +
1;
52 $end = intval( $maxID / $numBlocks ) * ( $b +
1 );
54 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
55 "old_id>=$start AND old_id<=$end " .
56 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
57 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
59 foreach ( $res as $row ) {
60 resolveStub( $row->old_id
, $row->old_text
, $row->old_flags
);
67 * Resolve a history stub
69 function resolveStub( $id, $stubText, $flags ) {
70 $fname = 'resolveStub';
72 $stub = unserialize( $stubText );
73 $flags = explode( ',', $flags );
75 $dbr = wfGetDB( DB_SLAVE
);
76 $dbw = wfGetDB( DB_MASTER
);
78 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
79 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
83 # Get the (maybe) external row
84 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
85 array( 'old_id' => $stub->mOldId
, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
89 if ( !$externalRow ) {
90 # Object wasn't external
94 # Preserve the legacy encoding flag, but switch from object to external
95 if ( in_array( 'utf-8', $flags ) ) {
96 $newFlags = 'external,utf-8';
98 $newFlags = 'external';
102 # print "oldid=$id\n";
103 $dbw->update( 'text',
105 'old_flags' => $newFlags,
106 'old_text' => $externalRow->old_text
. '/' . $stub->mHash