X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2Fstorage%2FcheckStorage.php;h=8f55b882150381b3c901f6943b8b48cc6ebc2b72;hp=9045870da42992fdf5c64a9b7ca9acc0b580e071;hb=74426f3cf796b149f1ae445e41815bbe148640b2;hpb=8bb5a6c461c31ee5ce6874548246fc2c520686f6 diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 9045870da4..8f55b88215 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -100,8 +100,12 @@ class CheckStorage { $missingTextRows = array_flip( $this->oldIdMap ); $externalRevs = []; $objectRevs = []; - $res = $dbr->select( 'text', [ 'old_id', 'old_flags' ], - 'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', __METHOD__ ); + $res = $dbr->select( + 'text', + [ 'old_id', 'old_flags' ], + [ 'old_id' => $this->oldIdMap ], + __METHOD__ + ); foreach ( $res as $row ) { /** * @var $flags int @@ -134,41 +138,48 @@ class CheckStorage { // This is a known bug from 2004 // It's safe to just erase the old_flags field if ( $fix ) { - $this->error( 'fixed', "Warning: old_flags set to 0", $id ); + $this->addError( 'fixed', "Warning: old_flags set to 0", $id ); $dbw = wfGetDB( DB_MASTER ); $dbw->ping(); $dbw->update( 'text', [ 'old_flags' => '' ], [ 'old_id' => $id ], __METHOD__ ); echo "Fixed\n"; } else { - $this->error( 'fixable', "Warning: old_flags set to 0", $id ); + $this->addError( 'fixable', "Warning: old_flags set to 0", $id ); } } elseif ( count( array_diff( $flagArray, $knownFlags ) ) ) { - $this->error( 'unfixable', "Error: invalid flags field \"$flags\"", $id ); + $this->addError( 'unfixable', "Error: invalid flags field \"$flags\"", $id ); } } $dbr->freeResult( $res ); // Output errors for any missing text rows foreach ( $missingTextRows as $oldId => $revId ) { - $this->error( 'restore revision', "Error: missing text row", $oldId ); + $this->addError( 'restore revision', "Error: missing text row", $oldId ); } // Verify external revisions $externalConcatBlobs = []; $externalNormalBlobs = []; if ( count( $externalRevs ) ) { - $res = $dbr->select( 'text', [ 'old_id', 'old_flags', 'old_text' ], - [ 'old_id IN (' . implode( ',', $externalRevs ) . ')' ], __METHOD__ ); + $res = $dbr->select( + 'text', + [ 'old_id', 'old_flags', 'old_text' ], + [ 'old_id' => $externalRevs ], + __METHOD__ + ); foreach ( $res as $row ) { $urlParts = explode( '://', $row->old_text, 2 ); if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) { - $this->error( 'restore text', "Error: invalid URL \"{$row->old_text}\"", $row->old_id ); + $this->addError( 'restore text', "Error: invalid URL \"{$row->old_text}\"", $row->old_id ); continue; } list( $proto, ) = $urlParts; if ( $proto != 'DB' ) { - $this->error( 'restore text', "Error: invalid external protocol \"$proto\"", $row->old_id ); + $this->addError( + 'restore text', + "Error: invalid external protocol \"$proto\"", + $row->old_id ); continue; } $path = explode( '/', $row->old_text ); @@ -197,14 +208,19 @@ class CheckStorage { $blobsTable = $this->dbStore->getTable( $extDb ); $res = $extDb->select( $blobsTable, [ 'blob_id' ], - [ 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ], __METHOD__ ); + [ 'blob_id' => $blobIds ], + __METHOD__ + ); foreach ( $res as $row ) { unset( $xBlobIds[$row->blob_id] ); } $extDb->freeResult( $res ); // Print errors for missing blobs rows foreach ( $xBlobIds as $blobId => $oldId ) { - $this->error( 'restore text', "Error: missing target $blobId for one-part ES URL", $oldId ); + $this->addError( + 'restore text', + "Error: missing target $blobId for one-part ES URL", + $oldId ); } } } @@ -218,20 +234,20 @@ class CheckStorage { $res = $dbr->select( 'text', [ 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ], - [ 'old_id IN (' . implode( ',', $objectRevs ) . ')' ], + [ 'old_id' => $objectRevs ], __METHOD__ ); foreach ( $res as $row ) { $oldId = $row->old_id; $matches = []; if ( !preg_match( '/^O:(\d+):"(\w+)"/', $row->header, $matches ) ) { - $this->error( 'restore text', "Error: invalid object header", $oldId ); + $this->addError( 'restore text', "Error: invalid object header", $oldId ); continue; } $className = strtolower( $matches[2] ); if ( strlen( $className ) != $matches[1] ) { - $this->error( + $this->addError( 'restore text', "Error: invalid object header, wrong class name length", $oldId @@ -249,12 +265,12 @@ class CheckStorage { case 'historyblobstub': case 'historyblobcurstub': if ( strlen( $row->header ) == $headerLength ) { - $this->error( 'unfixable', "Error: overlong stub header", $oldId ); + $this->addError( 'unfixable', "Error: overlong stub header", $oldId ); continue; } $stubObj = unserialize( $row->header ); if ( !is_object( $stubObj ) ) { - $this->error( 'restore text', "Error: unable to unserialize stub object", $oldId ); + $this->addError( 'restore text', "Error: unable to unserialize stub object", $oldId ); continue; } if ( $className == 'historyblobstub' ) { @@ -264,7 +280,7 @@ class CheckStorage { } break; default: - $this->error( 'unfixable', "Error: unrecognised object class \"$className\"", $oldId ); + $this->addError( 'unfixable', "Error: unrecognised object class \"$className\"", $oldId ); } } $dbr->freeResult( $res ); @@ -277,7 +293,7 @@ class CheckStorage { $res = $dbr->select( 'text', [ 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ], - [ 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ], + [ 'old_id' => array_keys( $concatBlobs ) ], __METHOD__ ); foreach ( $res as $row ) { @@ -287,7 +303,7 @@ class CheckStorage { if ( in_array( 'object', $flags ) ) { $urlParts = explode( '/', $row->header ); if ( $urlParts[0] != 'DB:' ) { - $this->error( + $this->addError( 'unfixable', "Error: unrecognised external storage type \"{$urlParts[0]}", $row->old_id @@ -303,7 +319,7 @@ class CheckStorage { ); } } else { - $this->error( + $this->addError( 'unfixable', "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}", $concatBlobs[$row->old_id] ); @@ -312,7 +328,7 @@ class CheckStorage { substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ), self::CONCAT_HEADER ) ) { - $this->error( + $this->addError( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}", $concatBlobs[$row->old_id] @@ -357,7 +373,7 @@ class CheckStorage { } } - function error( $type, $msg, $ids ) { + function addError( $type, $msg, $ids ) { if ( is_array( $ids ) && count( $ids ) == 1 ) { $ids = reset( $ids ); } @@ -396,10 +412,12 @@ class CheckStorage { $headerLength = strlen( self::CONCAT_HEADER ); $res = $extDb->select( $blobsTable, [ 'blob_id', "LEFT(blob_text, $headerLength) AS header" ], - [ 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ], __METHOD__ ); + [ 'blob_id' => $blobIds ], + __METHOD__ + ); foreach ( $res as $row ) { if ( strcasecmp( $row->header, self::CONCAT_HEADER ) ) { - $this->error( + $this->addError( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL", $oldIds[$row->blob_id] @@ -411,7 +429,7 @@ class CheckStorage { // Print errors for missing blobs rows foreach ( $oldIds as $blobId => $oldIds2 ) { - $this->error( + $this->addError( 'restore text', "Error: missing target $cluster/$blobId for two-part ES URL", $oldIds2 @@ -475,6 +493,9 @@ class CheckStorage { MediaWikiServices::getInstance()->getMainConfig() ); $importer->setRevisionCallback( [ $this, 'importRevision' ] ); + $importer->setNoticeCallback( function ( $msg, $params ) { + echo wfMessage( $msg, $params )->text() . "\n"; + } ); $importer->doImport(); }