Make update.php obey --quiet
authorPlatonides <platonides@users.mediawiki.org>
Wed, 27 Oct 2010 14:38:31 +0000 (14:38 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Wed, 27 Oct 2010 14:38:31 +0000 (14:38 +0000)
includes/installer/DatabaseUpdater.php
includes/installer/MysqlUpdater.php
maintenance/Maintenance.php
maintenance/update.php

index bb7bf11..5b8b9f0 100644 (file)
@@ -37,14 +37,20 @@ abstract class DatabaseUpdater {
         *
         * @param $db DatabaseBase object to perform updates on
         * @param $shared bool Whether to perform updates on shared tables
+        * @param $maintenance Maintenance Maintenance object which created us
         *
         * @TODO @FIXME Make $wgDatabase go away.
         */
-       protected function __construct( DatabaseBase &$db, $shared ) {
+       protected function __construct( DatabaseBase &$db, $shared, Maintenance $maintenance = null ) {
                global $wgDatabase;
                $wgDatabase = $db;
                $this->db = $db;
                $this->shared = $shared;
+               if ( $maintenance ) {
+                       $this->maintenance = $maintenance;
+               } else {
+                       $this->maintenance = new FakeMaintenance;
+               }
                $this->initOldGlobals();
                wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) );
        }
@@ -67,11 +73,11 @@ abstract class DatabaseUpdater {
                $wgExtModifiedFields = array(); // table, index, dir
        }
 
-       public static function newForDB( &$db, $shared = false ) {
+       public static function newForDB( &$db, $shared = false, $maintenance = null ) {
                $type = $db->getType();
                if( in_array( $type, Installer::getDBTypes() ) ) {
                        $class = ucfirst( $type ) . 'Updater';
-                       return new $class( $db, $shared );
+                       return new $class( $db, $shared, $maintenance );
                } else {
                        throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
                }
@@ -93,6 +99,9 @@ abstract class DatabaseUpdater {
         * @param $str String: Text to output
         */
        protected function output( $str ) {
+               if ( $this->maintenance->isQuiet() ) {
+                       return;
+               }
                wfOut( $str );
        }
 
@@ -210,7 +219,7 @@ abstract class DatabaseUpdater {
        /**
         * Before 1.17, we used to handle updates via stuff like
         * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
-        * of this in 1.17 but we want to remain back-compatible for awhile. So
+        * of this in 1.17 but we want to remain back-compatible for a while. So
         * load up these old global-based things into our update list.
         */
        protected function getOldGlobalUpdates() {
index 4550e05..1d18770 100644 (file)
@@ -253,7 +253,7 @@ class MysqlUpdater extends DatabaseUpdater {
        }
 
        protected function doOldLinksUpdate() {
-               $cl = new ConvertLinks();
+               $cl = $this->maintenance->runChild( 'ConvertLinks' );
                $cl->execute();
        }
 
@@ -696,7 +696,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $this->output( "ok\n" );
 
                $this->output( "Migrating old restrictions to new table...\n" );
-               $task = new UpdateRestrictions();
+               $task = $this->maintenance->runChild( 'UpdateRestrictions' );
                $task->execute();
        }
 
@@ -719,7 +719,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        "may want to hit Ctrl-C and do this manually with maintenance/\n" .
                        "populateCategory.php.\n"
                );
-               $task = new PopulateCategory();
+               $task = $this->maintenance->runChild( 'PopulateCategory' );
                $task->execute();
                $this->output( "Done populating category table.\n" );
        }
@@ -730,7 +730,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        return;
                }
 
-               $task = new PopulateParentId();
+               $task = $this->maintenance->runChild( 'PopulateParentId' );
                $task->execute();
        }
 
@@ -794,7 +794,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        return;
                }
 
-               $task = new PopulateRevisionLength();
+               $task = $this->maintenance->runChild( 'PopulateRevisionLength' );
                $task->execute();
        }
 
index 714f51f..1d0cc58 100644 (file)
@@ -229,6 +229,10 @@ abstract class Maintenance {
                return rtrim( $input );
        }
 
+       public function isQuiet() {
+               return $this->mQuiet;
+       }
+
        /**
         * Throw some output to the user. Scripts can call this with no fears,
         * as we handle all --quiet stuff here
@@ -366,7 +370,7 @@ abstract class Maintenance {
         * @param $classFile String: full path of where the child is
         * @return Maintenance child
         */
-       protected function runChild( $maintClass, $classFile = null ) {
+       public function runChild( $maintClass, $classFile = null ) {
                // If we haven't already specified, kill setup procedures
                // for child scripts, we've already got a sane environment
                self::disableSetup();
@@ -1032,3 +1036,10 @@ abstract class Maintenance {
        }
 
 }
+
+class FakeMaintenance extends Maintenance {
+       public function execute() {
+               return;
+       }
+}
+
index 57ce9aa..fe030ee 100644 (file)
@@ -64,7 +64,7 @@ class UpdateMediaWiki extends Maintenance {
                $shared = $this->hasOption( 'doshared' );
                $purge = !$this->hasOption( 'nopurge' );
 
-               $updater = DatabaseUpdater::newForDb( $db, $shared );
+               $updater = DatabaseUpdater::newForDb( $db, $shared, $this );
                $updater->doUpdates( $purge );
 
                foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {