Merge maintenance-work branch:
[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 require_once( "Maintenance.php" );
13
14 class PopulateLogSearch extends Maintenance {
15
16 const LOG_SEARCH_BATCH_SIZE = 100;
17
18 public function __construct() {
19 parent::__construct();
20 $this->mDescription = "Migrate log params to new table and index for searching";
21 }
22
23 public function execute() {
24 $db = wfGetDB( DB_MASTER );
25 if ( !$db->tableExists( 'log_search' ) ) {
26 $this->error( "log_search does not exist\n", true );
27 }
28 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
29 if( !$start ) {
30 $this->output( "Nothing to do.\n" );
31 return true;
32 }
33 $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
34
35 # Do remaining chunk
36 $end += self::LOG_SEARCH_BATCH_SIZE - 1;
37 $blockStart = $start;
38 $blockEnd = $start + self::LOG_SEARCH_BATCH_SIZE - 1;
39 while( $blockEnd <= $end ) {
40 $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
41 $cond = "log_id BETWEEN $blockStart AND $blockEnd";
42 $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
43 $batch = array();
44 while( $row = $db->fetchObject( $res ) ) {
45 // RevisionDelete logs - revisions
46 if( LogEventsList::typeAction( $row, array('delete','suppress'), 'revision' ) ) {
47 $params = LogPage::extractParams( $row->log_params );
48 // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
49 if( count($params) >= 2 ) {
50 $field = RevisionDeleter::getRelationType($params[0]);
51 // B/C, the params may start with a title key
52 if( $field == null ) {
53 array_shift($params);
54 $field = RevisionDeleter::getRelationType($params[0]);
55 }
56 if( $field == null ) {
57 $this->output( "Invalid param type for $row->log_id\n" );
58 continue; // skip this row
59 }
60 $items = explode(',',$params[1]);
61 $log = new LogPage( $row->log_type );
62 $log->addRelations( $field, $items, $row->log_id );
63 }
64 // RevisionDelete logs - log events
65 } else if( LogEventsList::typeAction( $row, array('delete','suppress'), 'event' ) ) {
66 $params = LogPage::extractParams( $row->log_params );
67 // Param format: <item CSV> [<ofield> <nfield>]
68 if( count($params) >= 1 ) {
69 $items = explode(',',$params[0]);
70 $log = new LogPage( $row->log_type );
71 $log->addRelations( 'log_id', $items, $row->log_id );
72 }
73 }
74 }
75 $blockStart += self::LOG_SEARCH_BATCH_SIZE;
76 $blockEnd += self::LOG_SEARCH_BATCH_SIZE;
77 wfWaitForSlaves( 5 );
78 }
79 if( $db->insert(
80 'updatelog',
81 array( 'ul_key' => 'populate log_search' ),
82 __FUNCTION__,
83 'IGNORE'
84 )
85 ) {
86 $this->output( "log_search population complete.\n" );
87 return true;
88 } else {
89 $this->output( "Could not insert log_search population row.\n" );
90 return false;
91 }
92 }
93 }
94
95 $maintClass = "PopulateLogSearch";
96 require_once( DO_MAINTENANCE );