http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96578
Revision: 96578
Author: demon
Date: 2011-09-08 15:52:00 +0000 (Thu, 08 Sep 2011)
Log Message:
-----------
Tweaks to LoggedUpdateMaintenance:
* Reduce some duplication
* Prefix skipped steps with "..." per updater convention
* Make PopulateLogUsertext, PopulateLogSearch and PopulateParentId use
LoggedUpdateMaintenance -- now they will properly log when there was "Nothing
to do" and we can skip the clutter on future update runs
* Docs, etc.
Modified Paths:
--------------
trunk/phase3/includes/installer/DatabaseUpdater.php
trunk/phase3/includes/installer/MysqlUpdater.php
trunk/phase3/maintenance/Maintenance.php
trunk/phase3/maintenance/populateImageSha1.php
trunk/phase3/maintenance/populateLogSearch.php
trunk/phase3/maintenance/populateLogUsertext.php
trunk/phase3/maintenance/populateParentId.php
trunk/phase3/maintenance/populateRevisionLength.php
Modified: trunk/phase3/includes/installer/DatabaseUpdater.php
===================================================================
--- trunk/phase3/includes/installer/DatabaseUpdater.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/includes/installer/DatabaseUpdater.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -519,33 +519,25 @@
}
protected function doLogUsertextPopulation() {
- if ( $this->updateRowExists( 'populate log_usertext' ) ) {
- $this->output( "...log_user_text field already
populated.\n" );
- return;
- }
-
- $this->output(
+ if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
+ $this->output(
"Populating log_user_text field, printing progress
markers. For large\n" .
"databases, you may want to hit Ctrl-C and do this
manually with\n" .
"maintenance/populateLogUsertext.php.\n" );
+ }
$task = $this->maintenance->runChild( 'PopulateLogUsertext' );
$task->execute();
- $this->output( "Done populating log_user_text field.\n" );
}
protected function doLogSearchPopulation() {
- if ( $this->updateRowExists( 'populate log_search' ) ) {
- $this->output( "...log_search table already
populated.\n" );
- return;
+ if ( !$this->updateRowExists( 'populate log_search' ) ) {
+ $this->output(
+ "Populating log_search table, printing progress
markers. For large\n" .
+ "databases, you may want to hit Ctrl-C and do
this manually with\n" .
+ "maintenance/populateLogSearch.php.\n" );
}
-
- $this->output(
- "Populating log_search table, printing progress
markers. For large\n" .
- "databases, you may want to hit Ctrl-C and do this
manually with\n" .
- "maintenance/populateLogSearch.php.\n" );
$task = $this->maintenance->runChild( 'PopulateLogSearch' );
$task->execute();
- $this->output( "Done populating log_search table.\n" );
}
protected function doUpdateTranscacheField() {
Modified: trunk/phase3/includes/installer/MysqlUpdater.php
===================================================================
--- trunk/phase3/includes/installer/MysqlUpdater.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/includes/installer/MysqlUpdater.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -747,11 +747,12 @@
}
protected function doPopulateParentId() {
- if ( $this->updateRowExists( 'populate rev_parent_id' ) ) {
- $this->output( "...rev_parent_id column already
populated.\n" );
- return;
+ if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) {
+ $this->output(
+ "Populating rev_parent_id fields, printing
progress markers. For large\n" .
+ "databases, you may want to hit Ctrl-C and do
this manually with\n" .
+ "maintenance/populateParentId.php.\n" );
}
-
$task = $this->maintenance->runChild( 'PopulateParentId' );
$task->execute();
}
Modified: trunk/phase3/maintenance/Maintenance.php
===================================================================
--- trunk/phase3/maintenance/Maintenance.php 2011-09-08 15:33:06 UTC (rev
96577)
+++ trunk/phase3/maintenance/Maintenance.php 2011-09-08 15:52:00 UTC (rev
96578)
@@ -1224,6 +1224,9 @@
}
}
+/**
+ * Fake maintenance wrapper, mostly used for the web installer/updater
+ */
class FakeMaintenance extends Maintenance {
protected $mSelf = "FakeMaintenanceScript";
public function execute() {
@@ -1231,10 +1234,15 @@
}
}
+/**
+ * Class for scripts that perform database maintenance and want to log the
+ * update in `updatelog` so we can later skip it
+ */
abstract class LoggedUpdateMaintenance extends Maintenance {
public function __construct() {
parent::__construct();
$this->addOption( 'force', 'Run the update even if it was
completed already' );
+ $this->setBatchSize( 200 );
}
public function execute() {
@@ -1244,7 +1252,7 @@
if ( !$this->hasOption( 'force' ) &&
$db->selectRow( 'updatelog', '1', array( 'ul_key' =>
$key ), __METHOD__ ) )
{
- $this->output( $this->updateSkippedMessage() . "\n" );
+ $this->output( "..." . $this->updateSkippedMessage() .
"\n" );
return true;
}
@@ -1263,6 +1271,15 @@
}
/**
+ * Message to show the the update log was unable to log the completion
of this update
+ * @return String
+ */
+ protected function updatelogFailedMessage() {
+ $key = $this->getUpdateKey();
+ return "Unable to log update '{$key}' as completed.";
+ }
+
+ /**
* Do the actual work. All child classes will need to implement this.
* Return true to log the update as done or false (usually on failure).
* @return Bool
@@ -1280,10 +1297,4 @@
* @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();
}
Modified: trunk/phase3/maintenance/populateImageSha1.php
===================================================================
--- trunk/phase3/maintenance/populateImageSha1.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/maintenance/populateImageSha1.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -29,7 +29,6 @@
$this->addOption( 'method', "Use 'pipe' to pipe to mysql
command line,\n" .
"\t\tdefault uses Database class", false, true );
$this->addOption( 'file', 'Fix for a specific file, without
File: namespace prefixed', false, true );
- $this->setBatchSize( 200 );
}
protected function getUpdateKey() {
@@ -40,10 +39,6 @@
return 'img_sha1 column of image table already populated.';
}
- protected function updatelogFailedMessage() {
- return 'Could not insert img_sha1 population row.';
- }
-
public function doDBUpdates() {
$method = $this->getOption( 'method', 'normal' );
$file = $this->getOption( 'file' );
Modified: trunk/phase3/maintenance/populateLogSearch.php
===================================================================
--- trunk/phase3/maintenance/populateLogSearch.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/maintenance/populateLogSearch.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -23,21 +23,28 @@
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
-class PopulateLogSearch extends Maintenance {
-
- const LOG_SEARCH_BATCH_SIZE = 100;
-
+class PopulateLogSearch extends LoggedUpdateMaintenance {
static $tableMap = array( 'rev' => 'revision', 'fa' => 'filearchive',
'oi' => 'oldimage', 'ar' => 'archive' );
public function __construct() {
parent::__construct();
$this->mDescription = "Migrate log params to new table and
index for searching";
+ $this->setBatchSize( 100 );
}
- public function execute() {
+ protected function getUpdateKey() {
+ return 'populate log_search';
+ }
+
+ protected function updateSkippedMessage() {
+ return 'log_search table already populated.';
+ }
+
+ protected function doDBUpdates() {
$db = $this->getDB( DB_MASTER );
if ( !$db->tableExists( 'log_search' ) ) {
- $this->error( "log_search does not exist", true );
+ $this->error( "log_search does not exist" );
+ return false;
}
$start = $db->selectField( 'logging', 'MIN(log_id)', false,
__FUNCTION__ );
if ( !$start ) {
@@ -47,9 +54,9 @@
$end = $db->selectField( 'logging', 'MAX(log_id)', false,
__FUNCTION__ );
# Do remaining chunk
- $end += self::LOG_SEARCH_BATCH_SIZE - 1;
+ $end += $this->mBatchSize - 1;
$blockStart = $start;
- $blockEnd = $start + self::LOG_SEARCH_BATCH_SIZE - 1;
+ $blockEnd = $start + $this->mBatchSize - 1;
$delTypes = array( 'delete', 'suppress' ); // revisiondelete
types
while ( $blockEnd <= $end ) {
@@ -128,23 +135,12 @@
$log->addRelations( 'target_author_ip',
$userIPs, $row->log_id );
}
}
- $blockStart += self::LOG_SEARCH_BATCH_SIZE;
- $blockEnd += self::LOG_SEARCH_BATCH_SIZE;
+ $blockStart += $this->mBatchSize;
+ $blockEnd += $this->mBatchSize;
wfWaitForSlaves();
}
- if ( $db->insert(
- 'updatelog',
- array( 'ul_key' => 'populate log_search' ),
- __FUNCTION__,
- 'IGNORE'
- )
- ) {
- $this->output( "log_search population complete.\n" );
- return true;
- } else {
- $this->output( "Could not insert log_search population
row.\n" );
- return false;
- }
+ $this->output( "Done populating log_search table.\n" );
+ return true;
}
}
Modified: trunk/phase3/maintenance/populateLogUsertext.php
===================================================================
--- trunk/phase3/maintenance/populateLogUsertext.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/maintenance/populateLogUsertext.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -25,14 +25,22 @@
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
-class PopulateLogUsertext extends Maintenance {
+class PopulateLogUsertext extends LoggedUpdateMaintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Populates the log_user_text";
+ $this->mDescription = "Populates the log_user_text field";
$this->setBatchSize( 100 );
}
- public function execute() {
+ protected function getUpdateKey() {
+ return 'populate log_usertext';
+ }
+
+ protected function updateSkippedMessage() {
+ return 'log_user_text column of logging table already
populated.';
+ }
+
+ protected function doDBUpdates() {
$db = $this->getDB( DB_MASTER );
$start = $db->selectField( 'logging', 'MIN(log_id)', false,
__METHOD__ );
if ( !$start ) {
@@ -61,19 +69,8 @@
$blockEnd += $this->mBatchSize;
wfWaitForSlaves();
}
- if ( $db->insert(
- 'updatelog',
- array( 'ul_key' => 'populate log_usertext' ),
- __METHOD__,
- 'IGNORE'
- )
- ) {
- $this->output( "log_usertext population complete.\n" );
- return true;
- } else {
- $this->output( "Could not insert log_usertext
population row.\n" );
- return false;
- }
+ $this->output( "Done populating log_user_text field.\n" );
+ return true;
}
}
Modified: trunk/phase3/maintenance/populateParentId.php
===================================================================
--- trunk/phase3/maintenance/populateParentId.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/maintenance/populateParentId.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -24,28 +24,32 @@
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
-class PopulateParentId extends Maintenance {
+class PopulateParentId extends LoggedUpdateMaintenance {
public function __construct() {
parent::__construct();
$this->mDescription = "Populates rev_parent_id";
- $this->setBatchSize( 200 );
}
- public function execute() {
+ protected function getUpdateKey() {
+ return 'populate rev_parent_id';
+ }
+
+ protected function updateSkippedMessage() {
+ return 'rev_parent_id column of revision table already
populated.';
+ }
+
+ protected function doDBUpdates() {
$db = wfGetDB( DB_MASTER );
if ( !$db->tableExists( 'revision' ) ) {
- $this->error( "revision table does not exist", true );
+ $this->error( "revision table does not exist" );
+ return false;
}
$this->output( "Populating rev_parent_id 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 ) ) {
- $this->output( "...revision table seems to be empty.\n"
);
- $db->insert( 'updatelog',
- array( 'ul_key' => 'populate rev_parent_id' ),
- __METHOD__,
- 'IGNORE' );
- return;
+ $this->output( "...revision table seems to be empty,
nothing to do.\n" );
+ return true;
}
# Do remaining chunk
$blockStart = intval( $start );
@@ -100,17 +104,8 @@
$blockEnd += $this->mBatchSize;
wfWaitForSlaves();
}
- $logged = $db->insert( 'updatelog',
- array( 'ul_key' => 'populate rev_parent_id' ),
- __METHOD__,
- 'IGNORE' );
- if ( $logged ) {
- $this->output( "rev_parent_id population complete ...
{$count} rows [{$changed} changed]\n" );
- return true;
- } else {
- $this->output( "Could not insert rev_parent_id
population row.\n" );
- return false;
- }
+ $this->output( "rev_parent_id population complete ... {$count}
rows [{$changed} changed]\n" );
+ return true;
}
}
Modified: trunk/phase3/maintenance/populateRevisionLength.php
===================================================================
--- trunk/phase3/maintenance/populateRevisionLength.php 2011-09-08 15:33:06 UTC
(rev 96577)
+++ trunk/phase3/maintenance/populateRevisionLength.php 2011-09-08 15:52:00 UTC
(rev 96578)
@@ -26,7 +26,6 @@
public function __construct() {
parent::__construct();
$this->mDescription = "Populates the rev_len field";
- $this->setBatchSize( 200 );
}
protected function getUpdateKey() {
@@ -37,10 +36,6 @@
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' ) ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs