From eb013851a5cdf81fae27e7e3807c7be635f94a02 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Thu, 25 Aug 2011 05:15:45 +0000 Subject: [PATCH] Move the check for if a Maintenance script supports --batch-size away from addDefaultParams() and to setBatchSize(), since setBatchSize is usually called in a subclass constructor after parent:__construct() which is after addDefaultParams() is called. Upside of this is lots of scripts supporting --batch-size now list it in their help output. --- RELEASE-NOTES-1.19 | 1 + maintenance/Maintenance.php | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index a7ce798a2f..82e30c58b1 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -72,6 +72,7 @@ production. used * (bug 28649) Avoiding half truncated multi-byte unicode characters when truncating log comments. +* Show --batch-size option in help of maintenance scripts that support it === API changes in 1.19 === * (bug 19838) siprop=interwikimap can now use the interwiki cache. diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 9cd853860c..36e9fa4bcc 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -248,6 +248,20 @@ abstract class Maintenance { */ protected function setBatchSize( $s = 0 ) { $this->mBatchSize = $s; + + // If we support $mBatchSize, show the option. + // Used to be in addDefaultParams, but in order for that to + // work, subclasses would have to call this function in the constructor + // before they called parent::__construct which is just weird + // (and really wasn't done). + if ( $this->mBatchSize ) { + $this->addOption( 'batch-size', 'Run this many operations ' . + 'per batch, default: ' . $this->mBatchSize, false, true ); + if ( isset( $this->mParams['batch-size'] ) ) { + // This seems a little ugly... + $this->mDependantParameters['batch-size'] = $this->mParams['batch-size']; + } + } } /** @@ -418,11 +432,7 @@ abstract class Maintenance { $this->addOption( 'dbuser', 'The DB user to use for this script', false, true ); $this->addOption( 'dbpass', 'The password to use for this script', false, true ); } - // If we support $mBatchSize, show the option - if ( $this->mBatchSize ) { - $this->addOption( 'batch-size', 'Run this many operations ' . - 'per batch, default: ' . $this->mBatchSize, false, true ); - } + # Save additional script dependant options to display # them separately in help $this->mDependantParameters = array_diff_key( $this->mParams, $this->mGenericParameters ); -- 2.20.1