24require_once __DIR__ .
'/../Maintenance.php';
38 parent::__construct();
39 $this->
addDescription(
'Script to fix T22757 assuming that blob_tracking is intact' );
40 $this->
addOption(
'dry-run',
'Report only' );
41 $this->
addOption(
'start',
'old_id to start at',
false,
true );
50 print "Dry run only.\n";
53 $startId = $this->
getOption(
'start', 0 );
58 $totalRevs =
$dbr->selectField(
'text',
'MAX(old_id)',
'', __METHOD__ );
61 $lowerLeft =
'LOWER(CONVERT(LEFT(old_text,22) USING latin1))';
64 print "ID: $startId / $totalRevs\r";
68 [
'old_id',
'old_flags',
'old_text' ],
70 'old_id > ' .
intval( $startId ),
71 'old_flags LIKE \'%object%\' AND old_flags NOT LIKE \'%external%\'',
72 "$lowerLeft = 'o:15:\"historyblobstub\"'",
76 'ORDER BY' =>
'old_id',
77 'LIMIT' => $this->batchSize,
81 if ( !
$res->numRows() ) {
88 foreach (
$res as $row ) {
89 $startId = $row->old_id;
93 if ( $obj ===
false ) {
94 print "{$row->old_id}: unrecoverable: cannot unserialize\n";
100 print "{$row->old_id}: unrecoverable: unserialized to type " .
101 gettype( $obj ) .
", possible double-serialization\n";
107 print "{$row->old_id}: unrecoverable: unexpected object class " .
114 $flags = explode(
',', $row->old_flags );
116 $legacyEncoding =
false;
118 $legacyEncoding =
true;
122 $id =
intval( $obj->mOldId );
123 $secondaryIds[] = $id;
124 $stubs[$row->old_id] = [
125 'legacyEncoding' => $legacyEncoding,
126 'secondaryId' => $id,
127 'hash' => $obj->mHash,
133 if ( !count( $secondaryIds ) ) {
142 'bt_text_id' => $secondaryIds,
147 foreach (
$res as $row ) {
148 $trackedBlobs[$row->bt_text_id] = $row;
152 foreach ( $stubs as $primaryId => $stub ) {
153 $secondaryId = $stub[
'secondaryId'];
154 if ( !
isset( $trackedBlobs[$secondaryId] ) ) {
156 $secondaryRow =
$dbr->selectRow(
158 [
'old_flags',
'old_text' ],
159 [
'old_id' => $secondaryId ],
162 if ( !$secondaryRow ) {
163 print "$primaryId: unrecoverable: secondary row is missing\n";
169 }
elseif (
strpos( $secondaryRow->old_flags,
'external' ) !==
false ) {
170 print "$primaryId: unrecoverable: secondary gone to {$secondaryRow->old_text}\n";
173 print "$primaryId: unrecoverable: miscellaneous corruption of secondary row\n";
176 unset( $stubs[$primaryId] );
182 $url =
"DB://{$trackRow->bt_cluster}/{$trackRow->bt_blob_id}/{$stub['hash']}";
183 $text = ExternalStore::fetchFromURL( $url );
184 if ( $text ===
false ) {
185 print "$primaryId: unrecoverable: source text missing\n";
187 unset( $stubs[$primaryId] );
190 if (
md5( $text ) !== $stub[
'hash'] ) {
191 print "$primaryId: unrecoverable: content hashes do not match\n";
193 unset( $stubs[$primaryId] );
199 $pageId =
intval( $trackRow->bt_page );
201 $revId = $pageId = 0;
206 $pageId = $revId = 0;
210 $newFlags = $stub[
'legacyEncoding'] ?
'external' :
'external,utf-8';
219 'old_flags' => $newFlags,
223 [
'old_id' => $primaryId ],
229 $dbw->insert(
'blob_tracking',
231 'bt_page' => $pageId,
232 'bt_rev_id' => $revId,
233 'bt_text_id' => $primaryId,
234 'bt_cluster' => $trackRow->bt_cluster,
235 'bt_blob_id' => $trackRow->bt_blob_id,
236 'bt_cgz_hash' => $stub[
'hash'],
237 'bt_new_url' =>
null,
245 print "$primaryId: resolved to $url\n";
251 print "Fixed: $numFixed\n";
252 print "Unrecoverable: $numBad\n";
253 print "Good stubs: $numGood\n";
262 if ( !
isset( $this->mapCache[$pageId] ) ) {
264 while ( $this->mapCacheSize > $this->maxMapCacheSize ) {
265 $key =
key( $this->mapCache );
266 $this->mapCacheSize -= count( $this->mapCache[$key] );
267 unset( $this->mapCache[$key] );
273 [
'rev_id',
'rev_text_id' ],
274 [
'rev_page' => $pageId ],
277 foreach (
$res as $row ) {
278 $map[$row->rev_text_id] = $row->rev_id;
280 $this->mapCache[$pageId] =
$map;
281 $this->mapCacheSize += count( $map );
284 return $this->mapCache[$pageId];
295 $flags = explode(
',', $secondaryRow->old_flags );
296 $text = $secondaryRow->old_text;
297 if (
in_array(
'external', $flags ) ) {
300 list( , $path ) = explode(
'://', $url, 2 );
306 $text = ExternalStore::fetchFromURL( $url );
308 if ( !
in_array(
'object', $flags ) ) {
328 $text = $obj->getItem( $stub[
'hash'] );
330 return $text !==
false;
unserialize( $serialized)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Maintenance script to fix T22757.
__construct()
Default constructor.
isUnbrokenStub( $stub, $secondaryRow)
This is based on part of HistoryBlobStub::getText().
findTextIdInPage( $pageId, $textId)
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
while(( $__line=Maintenance::readconsole()) !==false) print
require_once RUN_MAINTENANCE_IF_MAIN