]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/populateLogUsertext.php
MediaWiki 1.16.0
[autoinstalls/mediawiki.git] / maintenance / populateLogUsertext.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  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  * http://www.gnu.org/copyleft/gpl.html
22  *
23  * @ingroup Maintenance
24  */
25
26 require_once( dirname(__FILE__) . '/Maintenance.php' );
27
28 class PopulateLogUsertext extends Maintenance {
29         public function __construct() {
30                 parent::__construct();
31                 $this->mDescription = "Populates the log_user_text";
32                 $this->setBatchSize( 100 );
33         }
34
35         public function execute() {
36                 $db = wfGetDB( DB_MASTER );
37                 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
38                 if( !$start ) {
39                         $this->output( "Nothing to do.\n" );
40                         return true;
41                 }
42                 $end = $db->selectField( 'logging', 'MAX(log_id)', false, __METHOD__ );
43
44                 # Do remaining chunk
45                 $end += $this->mBatchSize - 1;
46                 $blockStart = $start;
47                 $blockEnd = $start + $this->mBatchSize - 1;
48                 while( $blockEnd <= $end ) {
49                         $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
50                         $cond = "log_id BETWEEN $blockStart AND $blockEnd AND log_user = user_id";
51                         $res = $db->select( array('logging','user'), 
52                                 array('log_id','user_name'), $cond, __METHOD__ );
53                         $batch = array();
54                         $db->begin();
55                         foreach( $res as $row ) {
56                                 $db->update( 'logging', array('log_user_text' => $row->user_name),
57                                         array('log_id' => $row->log_id), __METHOD__ );
58                         }
59                         $db->commit();
60                         $blockStart += $this->mBatchSize;
61                         $blockEnd += $this->mBatchSize;
62                         wfWaitForSlaves( 5 );
63                 }
64                 if( $db->insert(
65                                 'updatelog',
66                                 array( 'ul_key' => 'populate log_usertext' ),
67                                 __METHOD__,
68                                 'IGNORE'
69                         )
70                 ) {
71                         $this->output( "log_usertext population complete.\n" );
72                         return true;
73                 } else {
74                         $this->output( "Could not insert log_usertext population row.\n" );
75                         return false;
76                 }
77         }
78 }
79
80 $maintClass = "PopulateLogUsertext";
81 require_once( DO_MAINTENANCE );
82