X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2FpopulateContentTables.php;h=c84f3de54ecb80aef11ef1e50db316bbbe1db83e;hp=a264545e7f3c01e4b2f59f541905de0c16d23402;hb=6cfb2e3d7a2b96d5041312fcec88248bb46573d7;hpb=57f118c33689845d647c42e40bf4afda48610978 diff --git a/maintenance/populateContentTables.php b/maintenance/populateContentTables.php index a264545e7f..c84f3de54e 100644 --- a/maintenance/populateContentTables.php +++ b/maintenance/populateContentTables.php @@ -21,11 +21,12 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Revision\SlotRecord; +use MediaWiki\Storage\BlobStore; use MediaWiki\Storage\NameTableStore; use MediaWiki\Storage\SqlBlobStore; use Wikimedia\Assert\Assert; use Wikimedia\Rdbms\IDatabase; -use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IResultWrapper; require_once __DIR__ . '/Maintenance.php'; @@ -41,6 +42,9 @@ class PopulateContentTables extends Maintenance { /** @var NameTableStore */ private $contentModelStore; + /** @var BlobStore */ + private $blobStore; + /** @var int */ private $mainRoleId; @@ -67,6 +71,7 @@ class PopulateContentTables extends Maintenance { private function initServices() { $this->dbw = $this->getDB( DB_MASTER ); $this->contentModelStore = MediaWikiServices::getInstance()->getContentModelStore(); + $this->blobStore = MediaWikiServices::getInstance()->getBlobStore(); $this->mainRoleId = MediaWikiServices::getInstance()->getSlotRoleStore() ->acquireId( SlotRecord::MAIN ); } @@ -239,12 +244,12 @@ class PopulateContentTables extends Maintenance { } /** - * @param ResultWrapper $rows + * @param IResultWrapper $rows * @param int $startId * @param string $table * @return int|null */ - private function populateContentTablesForRowBatch( ResultWrapper $rows, $startId, $table ) { + private function populateContentTablesForRowBatch( IResultWrapper $rows, $startId, $table ) { $this->beginTransaction( $this->dbw, __METHOD__ ); if ( $this->contentRowMap === null ) { @@ -262,13 +267,16 @@ class PopulateContentTables extends Maintenance { Assert::invariant( $revisionId !== null, 'rev_id must not be null' ); - $modelId = $this->contentModelStore->acquireId( $this->getContentModel( $row ) ); + $model = $this->getContentModel( $row ); + $modelId = $this->contentModelStore->acquireId( $model ); $address = SqlBlobStore::makeAddressFromTextId( $row->text_id ); $key = "{$modelId}:{$address}"; $contentKeys[$revisionId] = $key; if ( !isset( $map[$key] ) ) { + $this->fillMissingFields( $row, $model, $address ); + $map[$key] = false; $contentRows[] = [ 'content_size' => (int)$row->len, @@ -345,6 +353,40 @@ class PopulateContentTables extends Maintenance { private function writeln( $msg ) { $this->output( "$msg\n" ); } + + /** + * Compute any missing fields in $row. + * The way the missing values are computed must correspond to the way this is done in SlotRecord. + * + * @param object $row to be modified + * @param string $model + * @param string $address + */ + private function fillMissingFields( $row, $model, $address ) { + if ( !isset( $row->content_model ) ) { + // just for completeness + $row->content_model = $model; + } + + if ( isset( $row->len ) && isset( $row->sha1 ) && $row->sha1 !== '' ) { + // No need to load the content, quite now. + return; + } + + $blob = $this->blobStore->getBlob( $address ); + + if ( !isset( $row->len ) ) { + // NOTE: The nominal size of the content may not be the length of the raw blob. + $handler = ContentHandler::getForModelID( $model ); + $content = $handler->unserializeContent( $blob ); + + $row->len = $content->getSize(); + } + + if ( !isset( $row->sha1 ) || $row->sha1 === '' ) { + $row->sha1 = SlotRecord::base36Sha1( $blob ); + } + } } $maintClass = 'PopulateContentTables';