Rudimentary hook benchmarks
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index 586b727..0dca74a 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 );
@@ -689,7 +699,7 @@ abstract class Maintenance {
                        $this->mQuiet = true;
                }
                if ( $this->hasOption( 'batch-size' ) ) {
-                       $this->mBatchSize = $this->getOption( 'batch-size' );
+                       $this->mBatchSize = intval( $this->getOption( 'batch-size' ) );
                }
        }
 
@@ -880,57 +890,6 @@ abstract class Maintenance {
                }
        }
 
-       /**
-        * Do setup specific to WMF
-        */
-       public function loadWikimediaSettings() {
-               global $IP, $wgNoDBParam, $wgUseNormalUser, $wgConf, $site, $lang;
-
-               if ( empty( $wgNoDBParam ) ) {
-                       # Check if we were passed a db name
-                       if ( isset( $this->mOptions['wiki'] ) ) {
-                               $db = $this->mOptions['wiki'];
-                       } else {
-                               $db = array_shift( $this->mArgs );
-                       }
-                       list( $site, $lang ) = $wgConf->siteFromDB( $db );
-
-                       # If not, work out the language and site the old way
-                       if ( is_null( $site ) || is_null( $lang ) ) {
-                               if ( !$db ) {
-                                       $lang = 'aa';
-                               } else {
-                                       $lang = $db;
-                               }
-                               if ( isset( $this->mArgs[0] ) ) {
-                                       $site = array_shift( $this->mArgs );
-                               } else {
-                                       $site = 'wikipedia';
-                               }
-                       }
-               } else {
-                       $lang = 'aa';
-                       $site = 'wikipedia';
-               }
-
-               # This is for the IRC scripts, which now run as the apache user
-               # The apache user doesn't have access to the wikiadmin_pass command
-               if ( $_ENV['USER'] == 'apache' ) {
-               # if ( posix_geteuid() == 48 ) {
-                       $wgUseNormalUser = true;
-               }
-
-               putenv( 'wikilang=' . $lang );
-
-               ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
-
-               if ( $lang == 'test' && $site == 'wikipedia' ) {
-                       if ( !defined( 'TESTWIKI' ) ) {
-                               define( 'TESTWIKI', 1 );
-                       }
-               }
-       }
-
        /**
         * Generic setup for most installs. Returns the location of LocalSettings
         * @return String
@@ -1199,7 +1158,7 @@ abstract class Maintenance {
                } else {
                        return posix_isatty( $fd );
                }
-}
+       }
 
        /**
         * Prompt the console for input
@@ -1265,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() {
@@ -1272,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() {
@@ -1285,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;
                }
 
@@ -1303,9 +1270,18 @@ 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 on failure.
+        * Return true to log the update as done or false (usually on failure).
         * @return Bool
         */
        abstract protected function doDBUpdates();
@@ -1321,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();
 }