* Moved PopulateRevisionLength/PopulateRevisionSha1 scripts to $postDatabaseUpdateMaintenance
* Fixed bogus "{$prefix}_sha1 != ''" comparison (r94362)
* Removed unneeded NOT NULL check (speeds up script a bit) from populateRevisionSha1 script
* Various code cleanups
'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc',
'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php',
'FakeMaintenance' => 'maintenance/Maintenance.php',
+ 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php',
'Maintenance' => 'maintenance/Maintenance.php',
'PopulateCategory' => 'maintenance/populateCategory.php',
'PopulateLogSearch' => 'maintenance/populateLogSearch.php',
protected $shared = false;
protected $postDatabaseUpdateMaintenance = array(
- 'DeleteDefaultMessages'
+ 'DeleteDefaultMessages',
+ 'PopulateRevisionLength',
+ 'PopulateRevisionSha1'
);
/**
$task = $this->maintenance->runChild( 'UpdateCollation' );
$task->execute();
}
-
- protected function doPopulateRevSha1() {
- if ( $this->updateRowExists( 'populate rev_sha1' ) ) {
- $this->output( "...rev_sha1/ar_sha1 columns already populated.\n" );
- return;
- }
-
- $task = $this->maintenance->runChild( 'PopulateRevisionSha1' );
- $task->execute();
- }
}
array( 'doUpdateTranscacheField' ),
array( 'renameEuWikiId' ),
array( 'doUpdateMimeMinorField' ),
- array( 'doPopulateRevLen' ),
// 1.17
array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ),
array( 'addTable', 'config', 'patch-config.sql' ),
array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'),
array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ),
- array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ),
- array( 'doPopulateRevSha1' )
+ array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' )
);
}
$this->output( "done.\n" );
}
- protected function doPopulateRevLen() {
- if ( $this->updateRowExists( 'populate rev_len' ) ) {
- $this->output( "...rev_len column already populated.\n" );
- return;
- }
-
- $task = $this->maintenance->runChild( 'PopulateRevisionLength' );
- $task->execute();
- }
-
protected function doClFieldsUpdate() {
if ( $this->updateRowExists( 'cl_fields_update' ) ) {
$this->output( "...categorylinks up-to-date.\n" );
return;
}
}
+
+abstract class LoggedUpdateMaintenance extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->addOption( 'force', 'Run the update even if it was completed already' );
+ }
+
+ public function execute() {
+ $db = $this->getDB( DB_MASTER );
+ $key = $this->getUpdateKey();
+
+ if ( !$this->hasOption( 'force' ) &&
+ $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ ) )
+ {
+ $this->output( $this->updateSkippedMessage() . "\n" );
+ return true;
+ }
+
+ if ( !$this->doDBUpdates() ) {
+ return false;
+ }
+
+ if (
+ $db->insert( 'updatelog', array( 'ul_key' => $key ), __METHOD__, 'IGNORE' ) )
+ {
+ return true;
+ } else {
+ $this->output( $this->updatelogFailedMessage() . "\n" );
+ return false;
+ }
+ }
+
+ /**
+ * Do the actual work. All child classes will need to implement this.
+ * Return true to log the update as done or false on failure.
+ * @return Bool
+ */
+ abstract protected function doDBUpdates();
+
+ /**
+ * Get the update key name to go in the update log table
+ * @return String
+ */
+ abstract protected function getUpdateKey();
+
+ /**
+ * Message to show that the update was done already and was just skipped
+ * @return String
+ */
+ abstract protected function updateSkippedMessage();
+
+ /**
+ * Message to show the the update log was unable to log the completion of this update
+ * @return String
+ */
+ abstract protected function updatelogFailedMessage();
+}
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
-class PopulateRevisionLength extends Maintenance {
+class PopulateRevisionLength extends LoggedUpdateMaintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Populates rev_len";
+ $this->mDescription = "Populates the rev_len field";
$this->setBatchSize( 200 );
}
- public function execute() {
+ protected function getUpdateKey() {
+ return 'populate rev_len';
+ }
+
+ protected function updateSkippedMessage() {
+ return 'rev_len column of revision table already populated.';
+ }
+
+ protected function updatelogFailedMessage() {
+ return 'Could not insert rev_len population row.';
+ }
+
+ public function doDBUpdates() {
$db = $this->getDB( DB_MASTER );
if ( !$db->tableExists( 'revision' ) ) {
$this->error( "revision table does not exist", true );
}
$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 ) ) {
+
+ $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__ );
+ $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
+ if ( !$start || !$end ) {
$this->output( "...revision table seems to be empty.\n" );
- $db->insert( 'updatelog',
- array( 'ul_key' => 'populate rev_len' ),
- __METHOD__,
- 'IGNORE' );
- return;
+ return true;
}
+
# Do remaining chunks
$blockStart = intval( $start );
$blockEnd = intval( $start ) + $this->mBatchSize - 1;
$blockEnd += $this->mBatchSize;
wfWaitForSlaves();
}
- $logged = $db->insert( 'updatelog',
- array( 'ul_key' => 'populate rev_len' ),
- __METHOD__,
- 'IGNORE' );
- 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" );
- return false;
- }
+
+ $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
+ return true;
}
}
<?php
/**
- * Fills the rev_sha1 and ar_sha1 columns of revision & archive tables.
+ * Fills the rev_sha1 and ar_sha1 columns of revision
+ * and archive tables for revisions created before MW 1.19.
*
* 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
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
-class PopulateRevisionSha1 extends Maintenance {
+class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
public function __construct() {
parent::__construct();
$this->mDescription = "Populates the rev_sha1 and ar_sha1 fields";
$this->setBatchSize( 200 );
}
- public function execute() {
+ protected function getUpdateKey() {
+ return 'populate rev_sha1';
+ }
+
+ protected function updateSkippedMessage() {
+ return 'rev_sha1 column of revision table already populated.';
+ }
+
+ protected function updatelogFailedMessage() {
+ return 'Could not insert rev_sha1 population row.';
+ }
+
+ protected function doDBUpdates() {
$db = $this->getDB( DB_MASTER );
+ if ( !$db->tableExists( 'revision' ) ) {
+ $this->error( "revision table does not exist", true );
+ }
+ if ( !$db->tableExists( 'archive' ) ) {
+ $this->error( "archive table does not exist", true );
+ }
$this->output( "Populating rev_sha1 column\n" );
- $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
+ $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
$this->output( "Populating ar_sha1 column\n" );
- $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
+ $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
- if ( $db->insert(
- 'updatelog',
- array( 'ul_key' => 'populate rev_sha1' ),
- __METHOD__,
- 'IGNORE'
- )
- ) {
- $this->output( "rev_sha1 and ar_sha1 population complete.\n" );
- return true;
- } else {
- $this->output( "Could not insert rev_sha1 population row.\n" );
- return false;
- }
+ $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" );
+ return true;
}
+ /**
+ * @return Integer Rows changed
+ */
protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
- $start = $db->selectField( $table, "MIN($idCol)", "$idCol IS NOT NULL", __METHOD__ );
- if ( !$start ) {
- $this->output( "Nothing to do.\n" );
+ $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ );
+ $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
+ if ( !$start || !$end ) {
+ $this->output( "...revision table seems to be empty.\n" );
return true;
}
- $end = $db->selectField( $table, "MAX($idCol)", "$idCol IS NOT NULL", __METHOD__ );
+ $count = 0;
# Do remaining chunk
$end += $this->mBatchSize - 1;
$blockStart = $start;
while ( $blockEnd <= $end ) {
$this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
$cond = "$idCol BETWEEN $blockStart AND $blockEnd
- AND $idCol IS NOT NULL AND {$prefix}_sha1 != ''";
+ AND $idCol IS NOT NULL AND {$prefix}_sha1 = ''";
$res = $db->select( $table, '*', $cond, __METHOD__ );
$db->begin();
array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ),
array( $idCol => $row->$idCol ),
__METHOD__ );
+ $count++;
}
}
$db->commit();
$blockEnd += $this->mBatchSize;
wfWaitForSlaves();
}
+ return $count;
}
}