X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FcheckStorage.php;h=173d741be86f48900efff7478a4058cd67f50c15;hb=0ffc58d935d4258dcb9411fa5e2f981dee7ca165;hp=a95789d3661304226f789cc41d7d6d1300275087;hpb=7ddab17aac1103fa080b50759ab6ca906caa554e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index a95789d366..173d741be8 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -22,6 +22,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; if ( !defined( 'MEDIAWIKI' ) ) { $optionsWithoutArgs = [ 'fix' ]; @@ -55,6 +56,8 @@ class CheckStorage { ]; function check( $fix = false, $xml = '' ) { + global $wgMultiContentRevisionSchemaMigrationStage; + $dbr = wfGetDB( DB_REPLICA ); if ( $fix ) { print "Checking, will fix errors if possible...\n"; @@ -78,33 +81,59 @@ class CheckStorage { $chunkEnd = $chunkStart + $chunkSize - 1; // print "$chunkStart of $maxRevId\n"; - // Fetch revision rows $this->oldIdMap = []; $dbr->ping(); - $res = $dbr->select( 'revision', [ 'rev_id', 'rev_text_id' ], - [ "rev_id BETWEEN $chunkStart AND $chunkEnd" ], __METHOD__ ); - foreach ( $res as $row ) { - $this->oldIdMap[$row->rev_id] = $row->rev_text_id; + + // Fetch revision rows + if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) { + $res = $dbr->select( 'revision', [ 'rev_id', 'rev_text_id' ], + [ "rev_id BETWEEN $chunkStart AND $chunkEnd" ], __METHOD__ ); + foreach ( $res as $row ) { + if ( !isset( $this->oldIdMap[ $row->rev_text_id ] ) ) { + $this->oldIdMap[ $row->rev_text_id ] = [ $row->rev_id ]; + } elseif ( !in_array( $row->rev_id, $this->oldIdMap[ $row->rev_text_id ] ) ) { + $this->oldIdMap[ $row->rev_text_id ][] = $row->rev_id; + } + } + } else { + $res = $dbr->select( + [ 'slots', 'content' ], + [ 'slot_revision_id', 'content_address' ], + [ "slot_revision_id BETWEEN $chunkStart AND $chunkEnd" ], + __METHOD__, + [], + [ 'content' => [ 'INNER JOIN', [ 'content_id = slot_content_id' ] ] ] + ); + $blobStore = MediaWikiServices::getInstance()->getBlobStore(); + foreach ( $res as $row ) { + $textId = $blobStore->getTextIdFromAddress( $row->content_address ); + if ( $textId ) { + if ( !isset( $this->oldIdMap[$textId] ) ) { + $this->oldIdMap[ $textId ] = [ $row->slot_revision_id ]; + } elseif ( !in_array( $row->slot_revision_id, $this->oldIdMap[$textId] ) ) { + $this->oldIdMap[ $textId ][] = $row->slot_revision_id; + } + } + } } - $dbr->freeResult( $res ); if ( !count( $this->oldIdMap ) ) { continue; } // Fetch old_flags - $missingTextRows = array_flip( $this->oldIdMap ); + $missingTextRows = $this->oldIdMap; $externalRevs = []; $objectRevs = []; $res = $dbr->select( 'text', [ 'old_id', 'old_flags' ], - [ 'old_id' => $this->oldIdMap ], + [ 'old_id' => array_keys( $this->oldIdMap ) ], __METHOD__ ); foreach ( $res as $row ) { /** - * @var $flags int + * @var int $flags */ $flags = $row->old_flags; $id = $row->old_id; @@ -147,10 +176,9 @@ class CheckStorage { $this->addError( 'unfixable', "Error: invalid flags field \"$flags\"", $id ); } } - $dbr->freeResult( $res ); // Output errors for any missing text rows - foreach ( $missingTextRows as $oldId => $revId ) { + foreach ( $missingTextRows as $oldId => $revIds ) { $this->addError( 'restore revision', "Error: missing text row", $oldId ); } @@ -187,7 +215,6 @@ class CheckStorage { $externalNormalBlobs[$cluster][$id][] = $row->old_id; } } - $dbr->freeResult( $res ); } // Check external concat blobs for the right header @@ -210,7 +237,6 @@ class CheckStorage { foreach ( $res as $row ) { unset( $xBlobIds[$row->blob_id] ); } - $extDb->freeResult( $res ); // Print errors for missing blobs rows foreach ( $xBlobIds as $blobId => $oldId ) { $this->addError( @@ -279,7 +305,6 @@ class CheckStorage { $this->addError( 'unfixable', "Error: unrecognised object class \"$className\"", $oldId ); } } - $dbr->freeResult( $res ); } // Check local concat blob validity @@ -333,7 +358,6 @@ class CheckStorage { unset( $concatBlobs[$row->old_id] ); } - $dbr->freeResult( $res ); } // Check targets of unresolved stubs @@ -376,13 +400,13 @@ class CheckStorage { if ( is_array( $ids ) ) { $revIds = []; foreach ( $ids as $id ) { - $revIds = array_merge( $revIds, array_keys( $this->oldIdMap, $id ) ); + $revIds = array_unique( array_merge( $revIds, $this->oldIdMap[$id] ) ); } print "$msg in text rows " . implode( ', ', $ids ) . ", revisions " . implode( ', ', $revIds ) . "\n"; } else { $id = $ids; - $revIds = array_keys( $this->oldIdMap, $id ); + $revIds = $this->oldIdMap[$id]; if ( count( $revIds ) == 1 ) { print "$msg in old_id $id, rev_id {$revIds[0]}\n"; } else { @@ -421,7 +445,6 @@ class CheckStorage { } unset( $oldIds[$row->blob_id] ); } - $extDb->freeResult( $res ); // Print errors for missing blobs rows foreach ( $oldIds as $blobId => $oldIds2 ) { @@ -458,7 +481,7 @@ class CheckStorage { echo "Filtering XML dump...\n"; $exitStatus = 0; passthru( 'mwdumper ' . - wfEscapeShellArg( + Shell::escape( "--output=file:$filteredXmlFileName", "--filter=revlist:$revFileName", $xml