r96012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96011‎ | r96012 | r96013 >
Date:16:55, 1 September 2011
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
RL2: Add maintenace script for populating the gadgetpagelist table
Modified paths:
  • /branches/RL2/extensions/Gadgets/populateGadgetPageList.php (added) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/populateGadgetPageList.php
@@ -0,0 +1,62 @@
 2+<?php
 3+
 4+$IP = getenv( 'MW_INSTALL_PATH' );
 5+if ( $IP === false ) {
 6+ $IP = dirname( __FILE__ ) . '/../..';
 7+}
 8+require( "$IP/maintenance/Maintenance.php" );
 9+
 10+class PopulateGadgetPageList extends Maintenance {
 11+ const BATCH_SIZE = 100;
 12+
 13+ public function __construct() {
 14+ parent::__construct();
 15+ $this->mDescription = "Populates the gadgetpagelist table";
 16+ }
 17+
 18+ public function execute() {
 19+ $dbr = wfGetDB( DB_SLAVE );
 20+ $dbw = wfGetDB( DB_MASTER );
 21+
 22+ $this->output( "Populating gadgetpagelist table ...\n" );
 23+
 24+ $lastPageID = 0;
 25+ $processed = 0;
 26+ $written = 0;
 27+ while ( true ) {
 28+ // Grab a batch of pages from the page table
 29+ $res = $dbr->select( 'page',
 30+ array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ),
 31+ "page_id > $lastPageID", __METHOD__,
 32+ array( 'LIMIT' => self::BATCH_SIZE, 'ORDER BY' => 'page_id' )
 33+ );
 34+ if ( $dbr->numRows( $res ) == 0 ) {
 35+ // We've reached the end
 36+ break;
 37+ }
 38+ $processed += $dbr->numRows( $res );
 39+
 40+ // Build gadgetpagelist rows
 41+ $gplRows = array();
 42+ foreach ( $res as $row ) {
 43+ $title = Title::newFromRow( $row );
 44+ if ( GadgetPageList::isGadgetPage( $title ) ) {
 45+ $gplRows[] = GadgetPageList::getRowForTitle( $title );
 46+ }
 47+ $lastPageID = intval( $row->page_id );
 48+ }
 49+ $dbr->freeResult( $res );
 50+
 51+ // Insert the new rows
 52+ $dbw->insert( 'gadgetpagelist', $gplRows, __METHOD__, array( 'IGNORE' ) );
 53+ $written += count( $gplRows );
 54+
 55+ $this->output( "... $processed pages processed, $written rows written, page_id $lastPageID\n" );
 56+ }
 57+
 58+ $this->output( "Done\n" );
 59+ }
 60+}
 61+
 62+$maintClass = "PopulateGadgetPageList";
 63+require_once( DO_MAINTENANCE );
\ No newline at end of file
Property changes on: branches/RL2/extensions/Gadgets/populateGadgetPageList.php
___________________________________________________________________
Added: svn:eol-style
164 + native

Sign-offs

UserFlagDate
Nikerabbitinspected20:15, 1 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r96879RL2: Followup r96012: use RUN_MAINTENANCE_IF_MAINcatrope18:33, 12 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   20:14, 1 September 2011

No RUN_MAINTENANCE_IF_MAIN?

#Comment by Catrope (talk | contribs)   13:44, 2 September 2011

Bah, this is what I get for copying my maintenance script skeleton from somewhere else.

#Comment by 😂 (talk | contribs)   13:47, 2 September 2011

Grrr, extensions should be updated :)

Status & tagging log