Remove evil @
[lhc/web/wiklou.git] / maintenance / populateRevisionLength.php
1 <?php
2 /*
3 * Populates the rev_len field for old revisions created before MW 1.10.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class PopulateRevisionLength extends LoggedUpdateMaintenance {
26 public function __construct() {
27 parent::__construct();
28 $this->mDescription = "Populates the rev_len field";
29 $this->setBatchSize( 200 );
30 }
31
32 protected function getUpdateKey() {
33 return 'populate rev_len';
34 }
35
36 protected function updateSkippedMessage() {
37 return 'rev_len column of revision table already populated.';
38 }
39
40 protected function updatelogFailedMessage() {
41 return 'Could not insert rev_len population row.';
42 }
43
44 public function doDBUpdates() {
45 $db = $this->getDB( DB_MASTER );
46 if ( !$db->tableExists( 'revision' ) ) {
47 $this->error( "revision table does not exist", true );
48 }
49 $this->output( "Populating rev_len column\n" );
50
51 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__ );
52 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
53 if ( !$start || !$end ) {
54 $this->output( "...revision table seems to be empty.\n" );
55 return true;
56 }
57
58 # Do remaining chunks
59 $blockStart = intval( $start );
60 $blockEnd = intval( $start ) + $this->mBatchSize - 1;
61 $count = 0;
62 $missing = 0;
63 while ( $blockStart <= $end ) {
64 $this->output( "...doing rev_id from $blockStart to $blockEnd\n" );
65 $res = $db->select( 'revision',
66 Revision::selectFields(),
67 array( "rev_id >= $blockStart",
68 "rev_id <= $blockEnd",
69 "rev_len IS NULL" ),
70 __METHOD__ );
71 # Go through and update rev_len from these rows.
72 foreach ( $res as $row ) {
73 $rev = new Revision( $row );
74 $text = $rev->getRawText();
75 if ( !is_string( $text ) ) {
76 # This should not happen, but sometimes does (bug 20757)
77 $this->output( "Text of revision {$row->rev_id} unavailable!\n" );
78 $missing++;
79 }
80 else {
81 # Update the row...
82 $db->update( 'revision',
83 array( 'rev_len' => strlen( $text ) ),
84 array( 'rev_id' => $row->rev_id ),
85 __METHOD__ );
86 $count++;
87 }
88 }
89 $blockStart += $this->mBatchSize;
90 $blockEnd += $this->mBatchSize;
91 wfWaitForSlaves();
92 }
93
94 $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
95 return true;
96 }
97 }
98
99 $maintClass = "PopulateRevisionLength";
100 require_once( RUN_MAINTENANCE_IF_MAIN );