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