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