3 * Populates the rev_len field for old revisions created before MW 1.10.
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.
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.
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
20 * @ingroup Maintenance
23 require_once( dirname( __FILE__
) . '/Maintenance.php' );
25 class PopulateRevisionLength
extends LoggedUpdateMaintenance
{
26 public function __construct() {
27 parent
::__construct();
28 $this->mDescription
= "Populates the rev_len field";
29 $this->setBatchSize( 200 );
32 protected function getUpdateKey() {
33 return 'populate rev_len';
36 protected function updateSkippedMessage() {
37 return 'rev_len column of revision table already populated.';
40 public function doDBUpdates() {
41 $db = $this->getDB( DB_MASTER
);
42 if ( !$db->tableExists( 'revision' ) ) {
43 $this->error( "revision table does not exist", true );
45 $this->output( "Populating rev_len column\n" );
47 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__
);
48 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__
);
49 if ( !$start ||
!$end ) {
50 $this->output( "...revision table seems to be empty.\n" );
55 $blockStart = intval( $start );
56 $blockEnd = intval( $start ) +
$this->mBatchSize
- 1;
59 while ( $blockStart <= $end ) {
60 $this->output( "...doing rev_id from $blockStart to $blockEnd\n" );
61 $res = $db->select( 'revision',
62 Revision
::selectFields(),
63 array( "rev_id >= $blockStart",
64 "rev_id <= $blockEnd",
67 # Go through and update rev_len from these rows.
68 foreach ( $res as $row ) {
69 $rev = new Revision( $row );
70 $text = $rev->getRawText();
71 if ( !is_string( $text ) ) {
72 # This should not happen, but sometimes does (bug 20757)
73 $this->output( "Text of revision {$row->rev_id} unavailable!\n" );
78 $db->update( 'revision',
79 array( 'rev_len' => strlen( $text ) ),
80 array( 'rev_id' => $row->rev_id
),
85 $blockStart +
= $this->mBatchSize
;
86 $blockEnd +
= $this->mBatchSize
;
90 $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
95 $maintClass = "PopulateRevisionLength";
96 require_once( RUN_MAINTENANCE_IF_MAIN
);