Index: branches/wmf/1.18wmf1/maintenance/fixPageFields.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Correct page fields with the revision table (page_latest=0) |
| 5 | + */ |
| 6 | + |
| 7 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 8 | + |
| 9 | +class FixPageFields extends Maintenance { |
| 10 | + public function __construct() { |
| 11 | + parent::__construct(); |
| 12 | + $this->mDescription = "Fix broken page rows with page_latest=0"; |
| 13 | + } |
| 14 | + |
| 15 | + public function execute() { |
| 16 | + $dbw = wfGetDB( DB_MASTER ); |
| 17 | + $res = $dbw->select( 'page', |
| 18 | + array( 'page_namespace', 'page_title', 'page_id' ), |
| 19 | + array( 'page_len' => 0, 'page_latest' => 0 ), |
| 20 | + __METHOD__ |
| 21 | + ); |
| 22 | + $fixLog = ''; |
| 23 | + $found = $fixed = 0; |
| 24 | + foreach ( $res as $row ) { |
| 25 | + $this->output( "Found page {$row->page_id}\n" ); |
| 26 | + $title = Title::newFromRow( $row ); |
| 27 | + $revRow = $dbw->selectRow( |
| 28 | + array( 'page', 'revision' ), |
| 29 | + Revision::selectFields(), |
| 30 | + array( 'page_id' => $row->page_id, 'page_id = rev_page', ), |
| 31 | + __METHOD__, |
| 32 | + array( 'ORDER BY' => 'rev_timestamp DESC' ) |
| 33 | + ); |
| 34 | + if ( $revRow ) { |
| 35 | + $article = new WikiPage( $title ); |
| 36 | + $revision = Revision::newFromRow( $revRow ); |
| 37 | + |
| 38 | + $dbw->begin(); |
| 39 | + $article->updateRevisionOn( $dbw, $revision, 0 /* page_latest */ ); |
| 40 | + if ( $revision->getParentId() ) { // updateRevisionOn() will set page_is_new=1 |
| 41 | + $dbw->update( 'page', |
| 42 | + array( 'page_is_new' => 0 ), // this is NOT new |
| 43 | + array( 'page_id' => $row->page_id ), |
| 44 | + __METHOD__ |
| 45 | + ); |
| 46 | + } |
| 47 | + $dbw->commit(); |
| 48 | + |
| 49 | + $fixed++; |
| 50 | + $fixLog .= $row->page_id . "\n"; |
| 51 | + } |
| 52 | + wfWaitForSlaves(); |
| 53 | + $found++; |
| 54 | + } |
| 55 | + file_put_contents( "fixPageFields-" . wfWikiID() . '-' . wfTimestampNow(), $fixLog ); |
| 56 | + $this->output( "Done! Found $found rows and fixed $fixed rows.\n" ); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +$maintClass = "FixPageFields"; |
| 61 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |