* @ingroup Maintenance
*/
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
class PopulateRevisionLength extends Maintenance {
public function __construct() {
$this->output( "Populating rev_len column\n" );
$start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
$end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
- if( is_null( $start ) || is_null( $end ) ){
+ if ( is_null( $start ) || is_null( $end ) ) {
$this->output( "...revision table seems to be empty.\n" );
$db->insert( 'updatelog',
array( 'ul_key' => 'populate rev_len' ),
$blockStart = intval( $start );
$blockEnd = intval( $start ) + $this->mBatchSize - 1;
$count = 0;
- while( $blockStart <= $end ) {
+ $missing = 0;
+ while ( $blockStart <= $end ) {
$this->output( "...doing rev_id from $blockStart to $blockEnd\n" );
$res = $db->select( 'revision',
Revision::selectFields(),
"rev_len IS NULL" ),
__METHOD__ );
# Go through and update rev_len from these rows.
- foreach( $res as $row ) {
+ foreach ( $res as $row ) {
$rev = new Revision( $row );
$text = $rev->getRawText();
- # Update the row...
- $db->update( 'revision',
- array( 'rev_len' => strlen( $text ) ),
- array( 'rev_id' => $row->rev_id ),
- __METHOD__ );
- $count++;
+ if ( !is_string( $text ) ) {
+ # This should not happen, but sometimes does (bug 20757)
+ $this->output( "Text of revision {$row->rev_id} unavailable!\n" );
+ $missing++;
+ }
+ else {
+ # Update the row...
+ $db->update( 'revision',
+ array( 'rev_len' => strlen( $text ) ),
+ array( 'rev_id' => $row->rev_id ),
+ __METHOD__ );
+ $count++;
+ }
}
$blockStart += $this->mBatchSize;
$blockEnd += $this->mBatchSize;
array( 'ul_key' => 'populate rev_len' ),
__METHOD__,
'IGNORE' );
- if( $logged ) {
- $this->output( "rev_len population complete ... {$count} rows changed\n" );
+ if ( $logged ) {
+ $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
return true;
} else {
$this->output( "Could not insert rev_len population row.\n" );