2010-03-03 20:23:42 +00:00
|
|
|
<?php
|
2011-10-11 18:30:50 +00:00
|
|
|
/**
|
2013-03-16 01:37:27 +00:00
|
|
|
* Populates the rev_len and ar_len fields for old revisions created
|
|
|
|
|
* before MW 1.10.
|
2010-03-03 20:23:42 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-08-20 14:55:28 +00:00
|
|
|
* @file
|
2010-03-03 20:23:42 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2010-03-03 20:23:42 +00:00
|
|
|
|
2012-08-20 14:55:28 +00:00
|
|
|
/**
|
2013-03-16 01:37:27 +00:00
|
|
|
* Maintenance script that populates the rev_len and ar_len fields
|
|
|
|
|
* for old revisions created before MW 1.10.
|
2012-08-20 14:55:28 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2011-08-15 18:52:25 +00:00
|
|
|
class PopulateRevisionLength extends LoggedUpdateMaintenance {
|
2010-03-03 20:23:42 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2013-03-16 01:37:27 +00:00
|
|
|
$this->mDescription = "Populates the rev_len and ar_len fields";
|
2011-10-27 18:32:52 +00:00
|
|
|
$this->setBatchSize( 200 );
|
2010-03-03 20:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-15 18:52:25 +00:00
|
|
|
protected function getUpdateKey() {
|
2013-03-16 01:37:27 +00:00
|
|
|
return 'populate rev_len and ar_len';
|
2011-08-15 18:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doDBUpdates() {
|
2011-05-24 17:48:22 +00:00
|
|
|
$db = $this->getDB( DB_MASTER );
|
2010-03-03 20:23:42 +00:00
|
|
|
if ( !$db->tableExists( 'revision' ) ) {
|
|
|
|
|
$this->error( "revision table does not exist", true );
|
2013-03-16 01:37:27 +00:00
|
|
|
} elseif ( !$db->tableExists( 'archive' ) ) {
|
|
|
|
|
$this->error( "archive table does not exist", true );
|
2013-04-17 14:52:47 +00:00
|
|
|
} elseif ( !$db->fieldExists( 'revision', 'rev_len', __METHOD__ ) ) {
|
2013-03-16 14:19:41 +00:00
|
|
|
$this->output( "rev_len column does not exist\n\n", true );
|
2014-04-23 18:09:13 +00:00
|
|
|
|
2012-11-22 03:53:24 +00:00
|
|
|
return false;
|
2010-03-03 20:23:42 +00:00
|
|
|
}
|
2012-11-22 03:53:24 +00:00
|
|
|
|
2010-03-03 20:23:42 +00:00
|
|
|
$this->output( "Populating rev_len column\n" );
|
2013-10-28 22:08:50 +00:00
|
|
|
$rev = $this->doLenUpdates( 'revision', 'rev_id', 'rev', Revision::selectFields() );
|
2013-03-16 01:37:27 +00:00
|
|
|
|
|
|
|
|
$this->output( "Populating ar_len column\n" );
|
2013-10-28 22:08:50 +00:00
|
|
|
$ar = $this->doLenUpdates( 'archive', 'ar_id', 'ar', Revision::selectArchiveFields() );
|
2013-03-16 01:37:27 +00:00
|
|
|
|
2014-04-22 21:07:08 +00:00
|
|
|
$this->output( "rev_len and ar_len population complete "
|
|
|
|
|
. "[$rev revision rows, $ar archive rows].\n" );
|
2014-04-23 18:09:13 +00:00
|
|
|
|
2013-03-16 01:37:27 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2011-08-15 18:52:25 +00:00
|
|
|
|
2013-03-16 01:37:27 +00:00
|
|
|
/**
|
2013-10-28 22:08:50 +00:00
|
|
|
* @param string $table
|
|
|
|
|
* @param string $idCol
|
|
|
|
|
* @param string $prefix
|
|
|
|
|
* @param array $fields
|
2013-03-16 01:37:27 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2013-10-28 22:08:50 +00:00
|
|
|
protected function doLenUpdates( $table, $idCol, $prefix, $fields ) {
|
2013-03-16 01:37:27 +00:00
|
|
|
$db = $this->getDB( DB_MASTER );
|
|
|
|
|
$start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ );
|
|
|
|
|
$end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
|
2011-08-15 18:52:25 +00:00
|
|
|
if ( !$start || !$end ) {
|
2013-03-16 01:37:27 +00:00
|
|
|
$this->output( "...$table table seems to be empty.\n" );
|
2014-04-23 18:09:13 +00:00
|
|
|
|
2013-03-16 01:37:27 +00:00
|
|
|
return 0;
|
2010-03-03 20:23:42 +00:00
|
|
|
}
|
2011-08-15 18:52:25 +00:00
|
|
|
|
2010-03-03 20:23:42 +00:00
|
|
|
# Do remaining chunks
|
|
|
|
|
$blockStart = intval( $start );
|
|
|
|
|
$blockEnd = intval( $start ) + $this->mBatchSize - 1;
|
|
|
|
|
$count = 0;
|
2013-10-28 22:08:50 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
while ( $blockStart <= $end ) {
|
2013-10-28 22:08:50 +00:00
|
|
|
$this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
|
2013-04-18 18:48:44 +00:00
|
|
|
$res = $db->select(
|
2013-03-16 01:37:27 +00:00
|
|
|
$table,
|
2013-04-18 18:48:44 +00:00
|
|
|
$fields,
|
|
|
|
|
array(
|
2013-03-16 01:37:27 +00:00
|
|
|
"$idCol >= $blockStart",
|
|
|
|
|
"$idCol <= $blockEnd",
|
|
|
|
|
"{$prefix}_len IS NULL"
|
2013-04-18 18:48:44 +00:00
|
|
|
),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2013-03-16 01:37:27 +00:00
|
|
|
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->beginTransaction( $db, __METHOD__ );
|
2010-03-03 20:23:42 +00:00
|
|
|
# Go through and update rev_len from these rows.
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $res as $row ) {
|
2013-03-16 01:37:27 +00:00
|
|
|
if ( $this->upgradeRow( $row, $table, $idCol, $prefix ) ) {
|
2010-03-04 00:27:44 +00:00
|
|
|
$count++;
|
|
|
|
|
}
|
2010-03-03 20:23:42 +00:00
|
|
|
}
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->commitTransaction( $db, __METHOD__ );
|
2013-03-16 01:37:27 +00:00
|
|
|
|
2010-03-03 20:23:42 +00:00
|
|
|
$blockStart += $this->mBatchSize;
|
|
|
|
|
$blockEnd += $this->mBatchSize;
|
2011-04-20 00:12:06 +00:00
|
|
|
wfWaitForSlaves();
|
2010-03-03 20:23:42 +00:00
|
|
|
}
|
2011-08-15 18:52:25 +00:00
|
|
|
|
2013-03-16 01:37:27 +00:00
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-17 20:48:32 +00:00
|
|
|
* @param stdClass $row
|
2013-10-28 22:08:50 +00:00
|
|
|
* @param string $table
|
|
|
|
|
* @param string $idCol
|
|
|
|
|
* @param string $prefix
|
2013-03-16 01:37:27 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function upgradeRow( $row, $table, $idCol, $prefix ) {
|
|
|
|
|
$db = $this->getDB( DB_MASTER );
|
|
|
|
|
|
|
|
|
|
$rev = ( $table === 'archive' )
|
|
|
|
|
? Revision::newFromArchiveRow( $row )
|
|
|
|
|
: new Revision( $row );
|
|
|
|
|
|
|
|
|
|
$content = $rev->getContent();
|
|
|
|
|
if ( !$content ) {
|
|
|
|
|
# This should not happen, but sometimes does (bug 20757)
|
|
|
|
|
$id = $row->$idCol;
|
|
|
|
|
$this->output( "Content of $table $id unavailable!\n" );
|
2014-04-23 18:09:13 +00:00
|
|
|
|
2013-03-16 01:37:27 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update the row...
|
|
|
|
|
$db->update( $table,
|
|
|
|
|
array( "{$prefix}_len" => $content->getSize() ),
|
|
|
|
|
array( $idCol => $row->$idCol ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
2011-08-15 18:52:25 +00:00
|
|
|
return true;
|
2010-03-03 20:23:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$maintClass = "PopulateRevisionLength";
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|