r50609 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50608‎ | r50609 | r50610 >
Date:23:06, 14 May 2009
Author:brion
Status:ok (Comments)
Tags:
Comment:
Populate log_search during update.php run and store an update status row when we're done.
Modified paths:
  • /trunk/phase3/maintenance/populateLogSearch.inc (added) (history)
  • /trunk/phase3/maintenance/populateLogSearch.php (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -158,6 +158,7 @@
159159 array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ),
160160 array( 'add_table', 'user_properties', 'patch-user_properties.sql' ),
161161 array( 'add_table', 'log_search', 'patch-log_search.sql' ),
 162+ array( 'do_log_search_population' ),
162163 ),
163164
164165 'sqlite' => array(
@@ -1305,6 +1306,21 @@
13061307 }
13071308 }
13081309
 1310+function do_log_search_population() {
 1311+ if( update_row_exists( 'populate log_search' ) ) {
 1312+ wfOut( "...log_search table already populated.\n" );
 1313+ return;
 1314+ }
 1315+ require_once( 'populateLogSearch.inc' );
 1316+ wfOut(
 1317+"Populating log_search table, printing progress markers. For large\n" .
 1318+"databases, you may want to hit Ctrl-C and do this manually with\n" .
 1319+"maintenance/populateLogSearch.php.\n" );
 1320+ $db =& wfGetDB( DB_MASTER );
 1321+ migrate_log_params( $db );
 1322+ wfOut( "Done populating log_search table.\n" );
 1323+}
 1324+
13091325 /***********************************************************************
13101326 * Start PG crap
13111327 * TODO: merge with above
Index: trunk/phase3/maintenance/populateLogSearch.inc
@@ -0,0 +1,80 @@
 2+<?php
 3+/**
 4+ * Makes the required database updates for Special:ProtectedPages
 5+ * to show all protected pages, even ones before the page restrictions
 6+ * schema change. All remaining page_restriction column values are moved
 7+ * to the new table.
 8+ *
 9+ * Run via update.php or directly through populateLogSearch.php
 10+ *
 11+ * @file
 12+ * @ingroup Maintenance
 13+ */
 14+
 15+define( 'LOG_SEARCH_BATCH_SIZE', 100 );
 16+
 17+function migrate_log_params( $db ) {
 18+ $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
 19+ if( !$start ) {
 20+ die("Nothing to do.\n");
 21+ }
 22+ $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
 23+
 24+ # Do remaining chunk
 25+ $end += LOG_SEARCH_BATCH_SIZE - 1;
 26+ $blockStart = $start;
 27+ $blockEnd = $start + LOG_SEARCH_BATCH_SIZE - 1;
 28+ while( $blockEnd <= $end ) {
 29+ echo "...doing log_id from $blockStart to $blockEnd\n";
 30+ $cond = "log_id BETWEEN $blockStart AND $blockEnd";
 31+ $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
 32+ $batch = array();
 33+ while( $row = $db->fetchObject( $res ) ) {
 34+ // RevisionDelete logs - revisions
 35+ if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
 36+ $params = LogPage::extractParams( $row->log_params );
 37+ // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
 38+ if( count($params) >= 2 ) {
 39+ $field = RevisionDeleter::getRelationType($params[0]);
 40+ // B/C, the params may start with a title key
 41+ if( $field == null ) {
 42+ array_shift($params);
 43+ $field = RevisionDeleter::getRelationType($params[0]);
 44+ }
 45+ if( $field == null ) {
 46+ echo "Invalid param type for $row->log_id";
 47+ continue; // skip this row
 48+ }
 49+ $items = explode(',',$params[1]);
 50+ $log = new LogPage( $row->log_type );
 51+ $log->addRelations( $field, $items, $row->log_id );
 52+ }
 53+ // RevisionDelete logs - log events
 54+ } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
 55+ $params = LogPage::extractParams( $row->log_params );
 56+ // Param format: <item CSV> [<ofield> <nfield>]
 57+ if( count($params) >= 1 ) {
 58+ $items = explode(',',$params[0]);
 59+ $log = new LogPage( $row->log_type );
 60+ $log->addRelations( 'log_id', $items, $row->log_id );
 61+ }
 62+ }
 63+ }
 64+ $blockStart += LOG_SEARCH_BATCH_SIZE - 1;
 65+ $blockEnd += LOG_SEARCH_BATCH_SIZE - 1;
 66+ wfWaitForSlaves( 5 );
 67+ }
 68+ if( $db->insert(
 69+ 'updatelog',
 70+ array( 'ul_key' => 'populate log_search' ),
 71+ __FUNCTION__,
 72+ 'IGNORE'
 73+ )
 74+ ) {
 75+ wfOut( "log_search population complete.\n" );
 76+ return true;
 77+ } else {
 78+ wfOut( "Could not insert log_search population row.\n" );
 79+ return false;
 80+ }
 81+}
Property changes on: trunk/phase3/maintenance/populateLogSearch.inc
___________________________________________________________________
Name: svn:eol-style
182 + native
Index: trunk/phase3/maintenance/populateLogSearch.php
@@ -9,9 +9,8 @@
1010 * @ingroup Maintenance
1111 */
1212
13 -define( 'BATCH_SIZE', 100 );
14 -
1513 require_once 'commandLine.inc';
 14+require_once 'populateLogSearch.inc';
1615
1716 $db =& wfGetDB( DB_MASTER );
1817 if ( !$db->tableExists( 'log_search' ) ) {
@@ -20,57 +19,3 @@
2120 }
2221
2322 migrate_log_params( $db );
24 -
25 -function migrate_log_params( $db ) {
26 - $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
27 - if( !$start ) {
28 - die("Nothing to do.\n");
29 - }
30 - $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
31 -
32 - # Do remaining chunk
33 - $end += BATCH_SIZE - 1;
34 - $blockStart = $start;
35 - $blockEnd = $start + BATCH_SIZE - 1;
36 - while( $blockEnd <= $end ) {
37 - echo "...doing log_id from $blockStart to $blockEnd\n";
38 - $cond = "log_id BETWEEN $blockStart AND $blockEnd";
39 - $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
40 - $batch = array();
41 - while( $row = $db->fetchObject( $res ) ) {
42 - // RevisionDelete logs - revisions
43 - if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
44 - $params = LogPage::extractParams( $row->log_params );
45 - // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
46 - if( count($params) >= 2 ) {
47 - $field = RevisionDeleter::getRelationType($params[0]);
48 - // B/C, the params may start with a title key
49 - if( $field == null ) {
50 - array_shift($params);
51 - $field = RevisionDeleter::getRelationType($params[0]);
52 - }
53 - if( $field == null ) {
54 - echo "Invalid param type for $row->log_id";
55 - continue; // skip this row
56 - }
57 - $items = explode(',',$params[1]);
58 - $log = new LogPage( $row->log_type );
59 - $log->addRelations( $field, $items, $row->log_id );
60 - }
61 - // RevisionDelete logs - log events
62 - } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
63 - $params = LogPage::extractParams( $row->log_params );
64 - // Param format: <item CSV> [<ofield> <nfield>]
65 - if( count($params) >= 1 ) {
66 - $items = explode(',',$params[0]);
67 - $log = new LogPage( $row->log_type );
68 - $log->addRelations( 'log_id', $items, $row->log_id );
69 - }
70 - }
71 - }
72 - $blockStart += BATCH_SIZE - 1;
73 - $blockEnd += BATCH_SIZE - 1;
74 - wfWaitForSlaves( 5 );
75 - }
76 - echo "...Done!\n";
77 -}

Follow-up revisions

RevisionCommit summaryAuthorDate
r50621Tweak for r50609: use $wgDatabase rather than wfGetDB( DB_MASTER )ialex09:37, 15 May 2009
r51528Don't kill whole update process if no log rows to update (fixes r50609)aaron00:39, 6 June 2009

Comments

#Comment by Tim Starling (talk | contribs)   11:14, 4 June 2009

Use wfOut() instead of echo in code targeted for both the web installer and the command line. This avoids XSS and calls flush() so that the output is sent to the user immediately instead of bufferred. It's also more likely to be forwards-compatible with the new installer.

Status & tagging log