From: Chad Horohoe Date: Thu, 8 Sep 2011 15:52:00 +0000 (+0000) Subject: Tweaks to LoggedUpdateMaintenance: X-Git-Tag: 1.31.0-rc.0~27792 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=41f7e84068c6f308b38fd8c9093032c7cb057364;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 38bbd42a7c..b20054dbbc 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -519,33 +519,25 @@ abstract class DatabaseUpdater { } 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() { diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 29d2673178..951acb66ee 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -747,11 +747,12 @@ class MysqlUpdater extends DatabaseUpdater { } 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(); } diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index adccee197a..0dca74ad2d 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1224,6 +1224,9 @@ abstract class Maintenance { } } +/** + * 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 FakeMaintenance extends Maintenance { } } +/** + * 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 @@ abstract class LoggedUpdateMaintenance extends Maintenance { 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; } @@ -1262,6 +1270,15 @@ abstract class LoggedUpdateMaintenance extends Maintenance { } } + /** + * 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). @@ -1280,10 +1297,4 @@ abstract class LoggedUpdateMaintenance extends Maintenance { * @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(); } diff --git a/maintenance/populateImageSha1.php b/maintenance/populateImageSha1.php index 4fee6fee5f..90fe82cfb5 100644 --- a/maintenance/populateImageSha1.php +++ b/maintenance/populateImageSha1.php @@ -29,7 +29,6 @@ class PopulateImageSha1 extends LoggedUpdateMaintenance { $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 @@ class PopulateImageSha1 extends LoggedUpdateMaintenance { 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' ); diff --git a/maintenance/populateLogSearch.php b/maintenance/populateLogSearch.php index f13873cb76..e3f6067fd8 100644 --- a/maintenance/populateLogSearch.php +++ b/maintenance/populateLogSearch.php @@ -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 ); + } + + protected function getUpdateKey() { + return 'populate log_search'; + } + + protected function updateSkippedMessage() { + return 'log_search table already populated.'; } - public function execute() { + 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 @@ class PopulateLogSearch extends Maintenance { $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 @@ class PopulateLogSearch extends Maintenance { $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; } } diff --git a/maintenance/populateLogUsertext.php b/maintenance/populateLogUsertext.php index e9e6926e7b..2b0e2d64c4 100644 --- a/maintenance/populateLogUsertext.php +++ b/maintenance/populateLogUsertext.php @@ -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 @@ class PopulateLogUsertext extends Maintenance { $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; } } diff --git a/maintenance/populateParentId.php b/maintenance/populateParentId.php index 7cbc267bbc..67689b9f6d 100644 --- a/maintenance/populateParentId.php +++ b/maintenance/populateParentId.php @@ -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 @@ class PopulateParentId extends Maintenance { $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; } } diff --git a/maintenance/populateRevisionLength.php b/maintenance/populateRevisionLength.php index ff053d1d39..bb42de93b6 100644 --- a/maintenance/populateRevisionLength.php +++ b/maintenance/populateRevisionLength.php @@ -26,7 +26,6 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { public function __construct() { parent::__construct(); $this->mDescription = "Populates the rev_len field"; - $this->setBatchSize( 200 ); } protected function getUpdateKey() { @@ -37,10 +36,6 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { 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' ) ) {