r54253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54252‎ | r54253 | r54254 >
Date:02:44, 3 August 2009
Author:demon
Status:ok
Tags:
Comment:
Re-add some files that are still used by updaters.inc.
Modified paths:
  • /trunk/phase3/maintenance/populateLogSearch.inc (added) (history)
  • /trunk/phase3/maintenance/populateParentId.inc (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/populateParentId.inc
@@ -0,0 +1,83 @@
 2+<?php
 3+
 4+define( 'BATCH_SIZE', 200 );
 5+
 6+function populate_rev_parent_id( $db ) {
 7+ wfOut( "Populating rev_parent_id column\n" );
 8+ $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
 9+ $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
 10+ if( is_null( $start ) || is_null( $end ) ){
 11+ wfOut( "...revision table seems to be empty.\n" );
 12+ $db->insert( 'updatelog',
 13+ array( 'ul_key' => 'populate rev_parent_id' ),
 14+ __FUNCTION__,
 15+ 'IGNORE' );
 16+ return;
 17+ }
 18+ # Do remaining chunk
 19+ $end += BATCH_SIZE - 1;
 20+ $blockStart = intval( $start );
 21+ $blockEnd = intval( $start ) + BATCH_SIZE - 1;
 22+ $count = 0;
 23+ $changed = 0;
 24+ while( $blockEnd <= $end ) {
 25+ wfOut( "...doing rev_id from $blockStart to $blockEnd\n" );
 26+ $cond = "rev_id BETWEEN $blockStart AND $blockEnd";
 27+ $res = $db->select( 'revision',
 28+ array('rev_id','rev_page','rev_timestamp','rev_parent_id'),
 29+ $cond, __FUNCTION__ );
 30+ # Go through and update rev_parent_id from these rows.
 31+ # Assume that the previous revision of the title was
 32+ # the original previous revision of the title when the
 33+ # edit was made...
 34+ foreach( $res as $row ) {
 35+ # First, check rows with the same timestamp other than this one
 36+ # with a smaller rev ID. The highest ID "wins". This avoids loops
 37+ # as timestamp can only decrease and never loops with IDs (from parent to parent)
 38+ $previousID = $db->selectField( 'revision', 'rev_id',
 39+ array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $row->rev_timestamp,
 40+ "rev_id < " . intval( $row->rev_id ) ),
 41+ __FUNCTION__,
 42+ array( 'ORDER BY' => 'rev_id DESC' ) );
 43+ # If there are none, check the the highest ID with a lower timestamp
 44+ if( !$previousID ) {
 45+ # Get the highest older timestamp
 46+ $lastTimestamp = $db->selectField( 'revision', 'rev_timestamp',
 47+ array( 'rev_page' => $row->rev_page, "rev_timestamp < " . $db->addQuotes( $row->rev_timestamp ) ),
 48+ __FUNCTION__,
 49+ array( 'ORDER BY' => 'rev_timestamp DESC' ) );
 50+ # If there is one, let the highest rev ID win
 51+ if( $lastTimestamp ) {
 52+ $previousID = $db->selectField( 'revision', 'rev_id',
 53+ array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $lastTimestamp ),
 54+ __FUNCTION__,
 55+ array( 'ORDER BY' => 'rev_id DESC' ) );
 56+ }
 57+ }
 58+ $previousID = intval($previousID);
 59+ if( $previousID != $row->rev_parent_id )
 60+ $changed++;
 61+ # Update the row...
 62+ $db->update( 'revision',
 63+ array( 'rev_parent_id' => $previousID ),
 64+ array( 'rev_id' => $row->rev_id ),
 65+ __FUNCTION__ );
 66+ $count++;
 67+ }
 68+ $blockStart += BATCH_SIZE - 1;
 69+ $blockEnd += BATCH_SIZE - 1;
 70+ wfWaitForSlaves( 5 );
 71+ }
 72+ $logged = $db->insert( 'updatelog',
 73+ array( 'ul_key' => 'populate rev_parent_id' ),
 74+ __FUNCTION__,
 75+ 'IGNORE' );
 76+ if( $logged ) {
 77+ wfOut( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
 78+ return true;
 79+ } else {
 80+ wfOut( "Could not insert rev_parent_id population row.\n" );
 81+ return false;
 82+ }
 83+}
 84+
Property changes on: trunk/phase3/maintenance/populateParentId.inc
___________________________________________________________________
Added: svn:mergeinfo
185 Merged /branches/REL1_15/phase3/maintenance/populateParentId.inc:r51646
Added: svn:eol-style
286 + native
Index: trunk/phase3/maintenance/populateLogSearch.inc
@@ -0,0 +1,78 @@
 2+<?php
 3+/**
 4+ * Makes the required database updates for log display in Special:RevisionDelete
 5+ *
 6+ * Run via update.php or directly through populateLogSearch.php
 7+ *
 8+ * @file
 9+ * @ingroup Maintenance
 10+ */
 11+
 12+define( 'LOG_SEARCH_BATCH_SIZE', 100 );
 13+
 14+function migrate_log_params( $db ) {
 15+ $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
 16+ if( !$start ) {
 17+ echo "Nothing to do.\n";
 18+ return true;
 19+ }
 20+ $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
 21+
 22+ # Do remaining chunk
 23+ $end += LOG_SEARCH_BATCH_SIZE - 1;
 24+ $blockStart = $start;
 25+ $blockEnd = $start + LOG_SEARCH_BATCH_SIZE - 1;
 26+ while( $blockEnd <= $end ) {
 27+ echo "...doing log_id from $blockStart to $blockEnd\n";
 28+ $cond = "log_id BETWEEN $blockStart AND $blockEnd";
 29+ $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
 30+ $batch = array();
 31+ while( $row = $db->fetchObject( $res ) ) {
 32+ // RevisionDelete logs - revisions
 33+ if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
 34+ $params = LogPage::extractParams( $row->log_params );
 35+ // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
 36+ if( count($params) >= 2 ) {
 37+ $field = RevisionDeleter::getRelationType($params[0]);
 38+ // B/C, the params may start with a title key
 39+ if( $field == null ) {
 40+ array_shift($params);
 41+ $field = RevisionDeleter::getRelationType($params[0]);
 42+ }
 43+ if( $field == null ) {
 44+ echo "Invalid param type for $row->log_id\n";
 45+ continue; // skip this row
 46+ }
 47+ $items = explode(',',$params[1]);
 48+ $log = new LogPage( $row->log_type );
 49+ $log->addRelations( $field, $items, $row->log_id );
 50+ }
 51+ // RevisionDelete logs - log events
 52+ } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
 53+ $params = LogPage::extractParams( $row->log_params );
 54+ // Param format: <item CSV> [<ofield> <nfield>]
 55+ if( count($params) >= 1 ) {
 56+ $items = explode(',',$params[0]);
 57+ $log = new LogPage( $row->log_type );
 58+ $log->addRelations( 'log_id', $items, $row->log_id );
 59+ }
 60+ }
 61+ }
 62+ $blockStart += LOG_SEARCH_BATCH_SIZE;
 63+ $blockEnd += LOG_SEARCH_BATCH_SIZE;
 64+ wfWaitForSlaves( 5 );
 65+ }
 66+ if( $db->insert(
 67+ 'updatelog',
 68+ array( 'ul_key' => 'populate log_search' ),
 69+ __FUNCTION__,
 70+ 'IGNORE'
 71+ )
 72+ ) {
 73+ wfOut( "log_search population complete.\n" );
 74+ return true;
 75+ } else {
 76+ wfOut( "Could not insert log_search population row.\n" );
 77+ return false;
 78+ }
 79+}
Property changes on: trunk/phase3/maintenance/populateLogSearch.inc
___________________________________________________________________
Added: svn:mergeinfo
180 Merged /branches/REL1_15/phase3/maintenance/populateLogSearch.inc:r51646
Added: svn:eol-style
281 + native

Status & tagging log