[schema change] Use new log_search table to replace ugly code from r48839. Maintenanc...
[lhc/web/wiklou.git] / maintenance / populateLogSearch.php
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 * @file
9 * @ingroup Maintenance
10 */
11
12 define( 'BATCH_SIZE', 100 );
13
14 require_once 'commandLine.inc';
15
16 $db =& wfGetDB( DB_MASTER );
17 if ( !$db->tableExists( 'log_search' ) ) {
18 echo "log_search does not exist\n";
19 exit( 1 );
20 }
21
22 migrate_log_params( $db );
23
24 function migrate_log_params( $db ) {
25 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
26 if( !$start ) {
27 die("Nothing to do.\n");
28 }
29 $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
30
31 # Do remaining chunk
32 $end += BATCH_SIZE - 1;
33 $blockStart = $start;
34 $blockEnd = $start + BATCH_SIZE - 1;
35 while( $blockEnd <= $end ) {
36 echo "...doing log_id from $blockStart to $blockEnd\n";
37 $cond = "log_id BETWEEN $blockStart AND $blockEnd";
38 $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
39 $batch = array();
40 while( $row = $db->fetchObject( $res ) ) {
41 // RevisionDelete logs - revisions
42 if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
43 $params = LogPage::extractParams( $row->log_params );
44 // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
45 if( count($params) >= 2 ) {
46 $field = RevisionDeleter::getRelationType($params[0]);
47 $items = explode(',',$params[1]);
48 $log = new LogPage( $row->log_type );
49 $log->addRelations( $field, $items, $row->log_id );
50 }
51 // RevisionDelete logs - log events
52 } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
53 $params = LogPage::extractParams( $row->log_params );
54 // Param format: <item CSV> [<ofield> <nfield>]
55 if( count($params) >= 1 ) {
56 $items = explode(',',$params[0]);
57 $log = new LogPage( $row->log_type );
58 $log->addRelations( 'log_id', $items, $row->log_id );
59 }
60 }
61 }
62 $blockStart += BATCH_SIZE - 1;
63 $blockEnd += BATCH_SIZE - 1;
64 wfWaitForSlaves( 5 );
65 }
66 echo "...Done!\n";
67 }