X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FcheckStorage.php;h=c2fa687432e29b12ee54e41aad6adab62e234897;hb=ac16588afe6b6067f2507b11f1025c0c339baab8;hp=eed8019ec26859e2becaf7dffab2dd067f16174d;hpb=27a6845c2a675990b04dfead674c0d46d140aa17;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index eed8019ec2..c2fa687432 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -45,6 +45,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class CheckStorage { const CONCAT_HEADER = 'O:27:"concatenatedgziphistoryblob"'; public $oldIdMap, $errors; + /** @var ExternalStoreDB */ public $dbStore = null; public $errorDescriptions = [ @@ -56,6 +57,8 @@ class CheckStorage { ]; function check( $fix = false, $xml = '' ) { + global $wgMultiContentRevisionSchemaMigrationStage; + $dbr = wfGetDB( DB_REPLICA ); if ( $fix ) { print "Checking, will fix errors if possible...\n"; @@ -79,13 +82,40 @@ 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; + } + } + } } if ( !count( $this->oldIdMap ) ) { @@ -93,13 +123,13 @@ class CheckStorage { } // 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 ) { @@ -149,7 +179,7 @@ class CheckStorage { } // 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 ); } @@ -194,7 +224,8 @@ class CheckStorage { // Check external normal blobs for existence if ( count( $externalNormalBlobs ) ) { if ( is_null( $this->dbStore ) ) { - $this->dbStore = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $this->dbStore = $esFactory->getStore( 'DB' ); } foreach ( $externalConcatBlobs as $cluster => $xBlobIds ) { $blobIds = array_keys( $xBlobIds ); @@ -371,13 +402,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 { @@ -393,7 +424,8 @@ class CheckStorage { } if ( is_null( $this->dbStore ) ) { - $this->dbStore = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $this->dbStore = $esFactory->getStore( 'DB' ); } foreach ( $externalConcatBlobs as $cluster => $oldIds ) {