MediaWiki REL1_35
resolveStubs.php
Go to the documentation of this file.
1<?php
26
27if ( !defined( 'MEDIAWIKI' ) ) {
28 $optionsWithArgs = [ 'm' ];
29
30 require_once __DIR__ . '/../commandLine.inc';
31
33}
34
39function resolveStubs() {
40 $fname = 'resolveStubs';
41
43 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', '', $fname );
44 $blockSize = 10000;
45 $numBlocks = intval( $maxID / $blockSize ) + 1;
46 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
47
48 for ( $b = 0; $b < $numBlocks; $b++ ) {
49 $lbFactory->waitForReplication();
50
51 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
52 $start = intval( $maxID / $numBlocks ) * $b + 1;
53 $end = intval( $maxID / $numBlocks ) * ( $b + 1 );
54
55 $res = $dbr->select( 'text', [ 'old_id', 'old_text', 'old_flags' ],
56 "old_id>=$start AND old_id<=$end " .
57 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
58 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
59 $fname );
60 foreach ( $res as $row ) {
61 resolveStub( $row->old_id, $row->old_text, $row->old_flags );
62 }
63 }
64 print "100%\n";
65}
66
73function resolveStub( $id, $stubText, $flags ) {
74 $fname = 'resolveStub';
75
76 $stub = unserialize( $stubText );
77 $flags = explode( ',', $flags );
78
80 $dbw = wfGetDB( DB_MASTER );
81
82 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
83 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
84
85 return;
86 }
87
88 # Get the (maybe) external row
89 $externalRow = $dbr->selectRow(
90 'text',
91 [ 'old_text' ],
92 [
93 'old_id' => $stub->getLocation(),
94 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() )
95 ],
96 $fname
97 );
98
99 if ( !$externalRow ) {
100 # Object wasn't external
101 return;
102 }
103
104 # Preserve the legacy encoding flag, but switch from object to external
105 if ( in_array( 'utf-8', $flags ) ) {
106 $newFlags = 'external,utf-8';
107 } else {
108 $newFlags = 'external';
109 }
110
111 # Update the row
112 # print "oldid=$id\n";
113 $dbw->update( 'text',
114 [ /* SET */
115 'old_flags' => $newFlags,
116 'old_text' => $externalRow->old_text . '/' . $stub->getHash()
117 ],
118 [ /* WHERE */
119 'old_id' => $id
120 ], $fname
121 );
122}
unserialize( $serialized)
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
MediaWikiServices is the service locator for the application scope of MediaWiki.
global $optionsWithArgs
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:29
resolveStub( $id, $stubText, $flags)
Resolve a history stub.
if(!defined('MEDIAWIKI')) resolveStubs()
Convert history stubs that point to an external row to direct external pointers.