Populate log_search during update.php run and store an update status row when we...
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 14 May 2009 23:06:53 +0000 (23:06 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 14 May 2009 23:06:53 +0000 (23:06 +0000)
maintenance/populateLogSearch.inc [new file with mode: 0644]
maintenance/populateLogSearch.php
maintenance/updaters.inc

diff --git a/maintenance/populateLogSearch.inc b/maintenance/populateLogSearch.inc
new file mode 100644 (file)
index 0000000..1f0a2bb
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Makes the required database updates for Special:ProtectedPages
+ * to show all protected pages, even ones before the page restrictions
+ * schema change. All remaining page_restriction column values are moved
+ * to the new table.
+ *
+ * Run via update.php or directly through populateLogSearch.php
+ *
+ * @file
+ * @ingroup Maintenance
+ */
+
+define( 'LOG_SEARCH_BATCH_SIZE', 100 );
+
+function migrate_log_params( $db ) {
+       $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
+       if( !$start ) {
+               die("Nothing to do.\n");
+       }
+       $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
+       
+       # Do remaining chunk
+       $end += LOG_SEARCH_BATCH_SIZE - 1;
+       $blockStart = $start;
+       $blockEnd = $start + LOG_SEARCH_BATCH_SIZE - 1;
+       while( $blockEnd <= $end ) {
+               echo "...doing log_id from $blockStart to $blockEnd\n";
+               $cond = "log_id BETWEEN $blockStart AND $blockEnd";
+               $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
+               $batch = array();
+               while( $row = $db->fetchObject( $res ) ) {
+                       // RevisionDelete logs - revisions
+                       if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
+                               $params = LogPage::extractParams( $row->log_params );
+                               // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
+                               if( count($params) >= 2 ) {
+                                       $field = RevisionDeleter::getRelationType($params[0]);
+                                       // B/C, the params may start with a title key
+                                       if( $field == null ) {
+                                               array_shift($params);
+                                               $field = RevisionDeleter::getRelationType($params[0]);
+                                       }
+                                       if( $field == null ) {
+                                               echo "Invalid param type for $row->log_id";
+                                               continue; // skip this row
+                                       }
+                                       $items = explode(',',$params[1]);
+                                       $log = new LogPage( $row->log_type );
+                                       $log->addRelations( $field, $items, $row->log_id );
+                               }
+                       // RevisionDelete logs - log events
+                       } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
+                               $params = LogPage::extractParams( $row->log_params );
+                               // Param format: <item CSV> [<ofield> <nfield>]
+                               if( count($params) >= 1 ) {
+                                       $items = explode(',',$params[0]);
+                                       $log = new LogPage( $row->log_type );
+                                       $log->addRelations( 'log_id', $items, $row->log_id );
+                               }
+                       }
+               }
+               $blockStart += LOG_SEARCH_BATCH_SIZE - 1;
+               $blockEnd += LOG_SEARCH_BATCH_SIZE - 1;
+               wfWaitForSlaves( 5 );
+       }
+       if( $db->insert(
+                       'updatelog',
+                       array( 'ul_key' => 'populate log_search' ),
+                       __FUNCTION__,
+                       'IGNORE'
+               )
+       ) {
+               wfOut( "log_search population complete.\n" );
+               return true;
+       } else {
+               wfOut( "Could not insert log_search population row.\n" );
+               return false;
+       }
+}
index 6205f7e..3679f7e 100644 (file)
@@ -9,9 +9,8 @@
  * @ingroup Maintenance
  */
 
-define( 'BATCH_SIZE', 100 );
-
 require_once 'commandLine.inc';
+require_once 'populateLogSearch.inc';
        
 $db =& wfGetDB( DB_MASTER );
 if ( !$db->tableExists( 'log_search' ) ) {
@@ -20,57 +19,3 @@ if ( !$db->tableExists( 'log_search' ) ) {
 }
 
 migrate_log_params( $db );
-
-function migrate_log_params( $db ) {
-       $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
-       if( !$start ) {
-               die("Nothing to do.\n");
-       }
-       $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
-       
-       # Do remaining chunk
-       $end += BATCH_SIZE - 1;
-       $blockStart = $start;
-       $blockEnd = $start + BATCH_SIZE - 1;
-       while( $blockEnd <= $end ) {
-               echo "...doing log_id from $blockStart to $blockEnd\n";
-               $cond = "log_id BETWEEN $blockStart AND $blockEnd";
-               $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
-               $batch = array();
-               while( $row = $db->fetchObject( $res ) ) {
-                       // RevisionDelete logs - revisions
-                       if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
-                               $params = LogPage::extractParams( $row->log_params );
-                               // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
-                               if( count($params) >= 2 ) {
-                                       $field = RevisionDeleter::getRelationType($params[0]);
-                                       // B/C, the params may start with a title key
-                                       if( $field == null ) {
-                                               array_shift($params);
-                                               $field = RevisionDeleter::getRelationType($params[0]);
-                                       }
-                                       if( $field == null ) {
-                                               echo "Invalid param type for $row->log_id";
-                                               continue; // skip this row
-                                       }
-                                       $items = explode(',',$params[1]);
-                                       $log = new LogPage( $row->log_type );
-                                       $log->addRelations( $field, $items, $row->log_id );
-                               }
-                       // RevisionDelete logs - log events
-                       } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
-                               $params = LogPage::extractParams( $row->log_params );
-                               // Param format: <item CSV> [<ofield> <nfield>]
-                               if( count($params) >= 1 ) {
-                                       $items = explode(',',$params[0]);
-                                       $log = new LogPage( $row->log_type );
-                                       $log->addRelations( 'log_id', $items, $row->log_id );
-                               }
-                       }
-               }
-               $blockStart += BATCH_SIZE - 1;
-               $blockEnd += BATCH_SIZE - 1;
-               wfWaitForSlaves( 5 );
-       }
-       echo "...Done!\n";
-}
index 72e510f..20b19f3 100644 (file)
@@ -158,6 +158,7 @@ $wgUpdates = array(
                array( 'add_table', 'valid_tag',                           'patch-change_tag.sql' ),
                array( 'add_table', 'user_properties',             'patch-user_properties.sql' ),
                array( 'add_table', 'log_search',                          'patch-log_search.sql' ),
+               array( 'do_log_search_population' ),
        ),
 
        'sqlite' => array(
@@ -1305,6 +1306,21 @@ function do_unique_pl_tl_il() {
        }
 }
 
+function do_log_search_population() {
+       if( update_row_exists( 'populate log_search' ) ) {
+               wfOut( "...log_search table already populated.\n" );
+               return;
+       }
+       require_once( 'populateLogSearch.inc' );
+       wfOut(
+"Populating log_search table, printing progress markers. For large\n" .
+"databases, you may want to hit Ctrl-C and do this manually with\n" .
+"maintenance/populateLogSearch.php.\n" );
+       $db =& wfGetDB( DB_MASTER );
+       migrate_log_params( $db );
+       wfOut( "Done populating log_search table.\n" );
+}
+
 /***********************************************************************
  * Start PG crap
  * TODO: merge with above