Move the check for if a Maintenance script supports --batch-size away from addDefault...
authorBrian Wolff <bawolff@users.mediawiki.org>
Thu, 25 Aug 2011 05:15:45 +0000 (05:15 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Thu, 25 Aug 2011 05:15:45 +0000 (05:15 +0000)
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
maintenance/Maintenance.php

index a7ce798..82e30c5 100644 (file)
@@ -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.
index 9cd8538..36e9fa4 100644 (file)
@@ -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 );