Add newline to echo call
[lhc/web/wiklou.git] / maintenance / populateLogSearch.inc
1 <?php
2 /**
3 * Makes the required database updates for Special:ProtectedPages
4 * to show all protected pages, even ones before the page restrictions
5 * schema change. All remaining page_restriction column values are moved
6 * to the new table.
7 *
8 * Run via update.php or directly through populateLogSearch.php
9 *
10 * @file
11 * @ingroup Maintenance
12 */
13
14 define( 'LOG_SEARCH_BATCH_SIZE', 100 );
15
16 function migrate_log_params( $db ) {
17 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
18 if( !$start ) {
19 die("Nothing to do.\n");
20 }
21 $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
22
23 # Do remaining chunk
24 $end += LOG_SEARCH_BATCH_SIZE - 1;
25 $blockStart = $start;
26 $blockEnd = $start + LOG_SEARCH_BATCH_SIZE - 1;
27 while( $blockEnd <= $end ) {
28 echo "...doing log_id from $blockStart to $blockEnd\n";
29 $cond = "log_id BETWEEN $blockStart AND $blockEnd";
30 $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
31 $batch = array();
32 while( $row = $db->fetchObject( $res ) ) {
33 // RevisionDelete logs - revisions
34 if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
35 $params = LogPage::extractParams( $row->log_params );
36 // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
37 if( count($params) >= 2 ) {
38 $field = RevisionDeleter::getRelationType($params[0]);
39 // B/C, the params may start with a title key
40 if( $field == null ) {
41 array_shift($params);
42 $field = RevisionDeleter::getRelationType($params[0]);
43 }
44 if( $field == null ) {
45 echo "Invalid param type for $row->log_id\n";
46 continue; // skip this row
47 }
48 $items = explode(',',$params[1]);
49 $log = new LogPage( $row->log_type );
50 $log->addRelations( $field, $items, $row->log_id );
51 }
52 // RevisionDelete logs - log events
53 } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
54 $params = LogPage::extractParams( $row->log_params );
55 // Param format: <item CSV> [<ofield> <nfield>]
56 if( count($params) >= 1 ) {
57 $items = explode(',',$params[0]);
58 $log = new LogPage( $row->log_type );
59 $log->addRelations( 'log_id', $items, $row->log_id );
60 }
61 }
62 }
63 $blockStart += LOG_SEARCH_BATCH_SIZE - 1;
64 $blockEnd += LOG_SEARCH_BATCH_SIZE - 1;
65 wfWaitForSlaves( 5 );
66 }
67 if( $db->insert(
68 'updatelog',
69 array( 'ul_key' => 'populate log_search' ),
70 __FUNCTION__,
71 'IGNORE'
72 )
73 ) {
74 wfOut( "log_search population complete.\n" );
75 return true;
76 } else {
77 wfOut( "Could not insert log_search population row.\n" );
78 return false;
79 }
80 }