X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpopulateContentModel.php;h=8d64dae3ab87e0dd926859f754dcce9f42783b86;hb=899f475d0dad8ea0a24f706fc8ac07e3097d6191;hp=b41e0e0d6e74551319085e9e02afbb06ed1e995f;hpb=490daba99cf1251b2950d11fa95a2d53f793540e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/populateContentModel.php b/maintenance/populateContentModel.php index b41e0e0d6e..8d64dae3ab 100644 --- a/maintenance/populateContentModel.php +++ b/maintenance/populateContentModel.php @@ -23,13 +23,16 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\IDatabase; +use MediaWiki\MediaWikiServices; + /** * Usage: * populateContentModel.php --ns=1 --table=page */ class PopulateContentModel extends Maintenance { protected $wikiId; - + /** @var WANObjectCache */ protected $wanCache; public function __construct() { @@ -43,13 +46,12 @@ class PopulateContentModel extends Maintenance { public function execute() { $dbw = $this->getDB( DB_MASTER ); - $this->wikiId = $dbw->getWikiID(); - - $this->wanCache = ObjectCache::getMainWANInstance(); + $this->wikiId = $dbw->getDomainID(); + $this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $ns = $this->getOption( 'ns' ); if ( !ctype_digit( $ns ) && $ns !== 'all' ) { - $this->error( 'Invalid namespace', 1 ); + $this->fatalError( 'Invalid namespace' ); } $ns = $ns === 'all' ? 'all' : (int)$ns; $table = $this->getOption( 'table' ); @@ -62,12 +64,12 @@ class PopulateContentModel extends Maintenance { $this->populatePage( $dbw, $ns ); break; default: - $this->error( "Invalid table name: $table", 1 ); + $this->fatalError( "Invalid table name: $table" ); } } protected function clearCache( $page_id, $rev_id ) { - $contentModelKey = $this->wanCache->makeKey( 'page', 'content-model', $rev_id ); + $contentModelKey = $this->wanCache->makeKey( 'page-content-model', $rev_id ); $revisionKey = $this->wanCache->makeGlobalKey( 'revision', $this->wikiId, $page_id, $rev_id ); @@ -78,7 +80,7 @@ class PopulateContentModel extends Maintenance { $this->wanCache->delete( $revisionKey ); } - private function updatePageRows( Database $dbw, $pageIds, $model ) { + private function updatePageRows( IDatabase $dbw, $pageIds, $model ) { $count = count( $pageIds ); $this->output( "Setting $count rows to $model..." ); $dbw->update( @@ -91,10 +93,11 @@ class PopulateContentModel extends Maintenance { $this->output( "done.\n" ); } - protected function populatePage( Database $dbw, $ns ) { + protected function populatePage( IDatabase $dbw, $ns ) { $toSave = []; $lastId = 0; $nsCondition = $ns === 'all' ? [] : [ 'page_namespace' => $ns ]; + $batchSize = $this->getBatchSize(); do { $rows = $dbw->select( 'page', @@ -104,26 +107,26 @@ class PopulateContentModel extends Maintenance { 'page_id > ' . $dbw->addQuotes( $lastId ), ] + $nsCondition, __METHOD__, - [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => 'page_id ASC' ] + [ 'LIMIT' => $batchSize, 'ORDER BY' => 'page_id ASC' ] ); $this->output( "Fetched {$rows->numRows()} rows.\n" ); foreach ( $rows as $row ) { $title = Title::newFromRow( $row ); $model = ContentHandler::getDefaultModelFor( $title ); $toSave[$model][] = $row->page_id; - if ( count( $toSave[$model] ) >= $this->mBatchSize ) { + if ( count( $toSave[$model] ) >= $batchSize ) { $this->updatePageRows( $dbw, $toSave[$model], $model ); unset( $toSave[$model] ); } $lastId = $row->page_id; } - } while ( $rows->numRows() >= $this->mBatchSize ); + } while ( $rows->numRows() >= $batchSize ); foreach ( $toSave as $model => $pages ) { $this->updatePageRows( $dbw, $pages, $model ); } } - private function updateRevisionOrArchiveRows( Database $dbw, $ids, $model, $table ) { + private function updateRevisionOrArchiveRows( IDatabase $dbw, $ids, $model, $table ) { $prefix = $table === 'archive' ? 'ar' : 'rev'; $model_column = "{$prefix}_content_model"; $format_column = "{$prefix}_content_format"; @@ -142,7 +145,7 @@ class PopulateContentModel extends Maintenance { $this->output( "done.\n" ); } - protected function populateRevisionOrArchive( Database $dbw, $table, $ns ) { + protected function populateRevisionOrArchive( IDatabase $dbw, $table, $ns ) { $prefix = $table === 'archive' ? 'ar' : 'rev'; $model_column = "{$prefix}_content_model"; $format_column = "{$prefix}_content_format"; @@ -166,6 +169,7 @@ class PopulateContentModel extends Maintenance { $toSave = []; $idsToClear = []; $lastId = 0; + $batchSize = $this->getBatchSize(); do { $rows = $dbw->select( $selectTables, @@ -179,7 +183,7 @@ class PopulateContentModel extends Maintenance { "$key > " . $dbw->addQuotes( $lastId ), ] + $where, __METHOD__, - [ 'LIMIT' => $this->mBatchSize, 'ORDER BY' => "$key ASC" ], + [ 'LIMIT' => $batchSize, 'ORDER BY' => "$key ASC" ], $join_conds ); $this->output( "Fetched {$rows->numRows()} rows.\n" ); @@ -230,12 +234,12 @@ class PopulateContentModel extends Maintenance { } } - if ( count( $toSave[$defaultModel] ) >= $this->mBatchSize ) { + if ( count( $toSave[$defaultModel] ) >= $batchSize ) { $this->updateRevisionOrArchiveRows( $dbw, $toSave[$defaultModel], $defaultModel, $table ); unset( $toSave[$defaultModel] ); } } - } while ( $rows->numRows() >= $this->mBatchSize ); + } while ( $rows->numRows() >= $batchSize ); foreach ( $toSave as $model => $ids ) { $this->updateRevisionOrArchiveRows( $dbw, $ids, $model, $table ); } @@ -246,5 +250,5 @@ class PopulateContentModel extends Maintenance { } } -$maintClass = 'PopulateContentModel'; +$maintClass = PopulateContentModel::class; require_once RUN_MAINTENANCE_IF_MAIN;