X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/maintenance/populateBacklinkNamespace.php diff --git a/maintenance/populateBacklinkNamespace.php b/maintenance/populateBacklinkNamespace.php new file mode 100644 index 00000000..295dacda --- /dev/null +++ b/maintenance/populateBacklinkNamespace.php @@ -0,0 +1,97 @@ +addDescription( 'Populate the *_from_namespace fields' ); + $this->addOption( 'lastUpdatedId', "Highest page_id with updated links", false, true ); + } + + protected function getUpdateKey() { + return 'populate *_from_namespace'; + } + + protected function updateSkippedMessage() { + return '*_from_namespace column of backlink tables already populated.'; + } + + public function doDBUpdates() { + $force = $this->getOption( 'force' ); + + $db = $this->getDB( DB_MASTER ); + + $this->output( "Updating *_from_namespace fields in links tables.\n" ); + + $start = $this->getOption( 'lastUpdatedId' ); + if ( !$start ) { + $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ ); + } + if ( !$start ) { + $this->output( "Nothing to do." ); + return false; + } + $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ ); + + # Do remaining chunk + $end += $this->mBatchSize - 1; + $blockStart = $start; + $blockEnd = $start + $this->mBatchSize - 1; + while ( $blockEnd <= $end ) { + $this->output( "...doing page_id from $blockStart to $blockEnd\n" ); + $cond = "page_id BETWEEN $blockStart AND $blockEnd"; + $res = $db->select( 'page', [ 'page_id', 'page_namespace' ], $cond, __METHOD__ ); + foreach ( $res as $row ) { + $db->update( 'pagelinks', + [ 'pl_from_namespace' => $row->page_namespace ], + [ 'pl_from' => $row->page_id ], + __METHOD__ + ); + $db->update( 'templatelinks', + [ 'tl_from_namespace' => $row->page_namespace ], + [ 'tl_from' => $row->page_id ], + __METHOD__ + ); + $db->update( 'imagelinks', + [ 'il_from_namespace' => $row->page_namespace ], + [ 'il_from' => $row->page_id ], + __METHOD__ + ); + } + $blockStart += $this->mBatchSize - 1; + $blockEnd += $this->mBatchSize - 1; + wfWaitForSlaves(); + } + return true; + } +} + +$maintClass = "PopulateBacklinkNamespace"; +require_once RUN_MAINTENANCE_IF_MAIN;