Set blank $fname
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index 14954cb..4688e7b 100644 (file)
@@ -5,7 +5,9 @@
  * @file
  * @ingroup Deployment
  */
+
+require_once( dirname(__FILE__) . '/../../maintenance/Maintenance.php' );
+
 /*
  * Class for handling database updates. Roughly based off of updaters.inc, with
  * a few improvements :)
@@ -37,14 +39,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.
+        * @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 +75,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' );
                }
@@ -86,6 +94,19 @@ abstract class DatabaseUpdater {
                return $this->db;
        }
 
+       /**
+        * Output some text. Right now this is a wrapper for wfOut, but hopefully
+        * that function can go away some day :)
+        *
+        * @param $str String: Text to output
+        */
+       protected function output( $str ) {
+               if ( $this->maintenance->isQuiet() ) {
+                       return;
+               }
+               wfOut( $str );
+       }
+
        /**
         * Add a new update coming from an extension. This should be called by
         * extensions while executing the LoadExtensionSchemaUpdates hook.
@@ -122,6 +143,10 @@ abstract class DatabaseUpdater {
        public function doUpdates( $purge = true ) {
                global $wgVersion;
 
+               if ( !defined( 'MW_NO_SETUP' ) ) {
+                       define( 'MW_NO_SETUP', true );
+               }
+
                $this->runUpdates( $this->getCoreUpdateList(), false );
                $this->runUpdates( $this->getOldGlobalUpdates(), false );
                $this->runUpdates( $this->getExtensionUpdates(), true );
@@ -196,7 +221,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() {
@@ -260,7 +285,7 @@ abstract class DatabaseUpdater {
                if ( $isFullPath ) {
                        $this->db->sourceFile( $path );
                } else {
-                       $this->db->sourceFile( DatabaseBase::patchPath( $path ) );
+                       $this->db->sourceFile( $this->db->patchPath( $path ) );
                }
        }
 
@@ -272,11 +297,11 @@ abstract class DatabaseUpdater {
         */
        protected function addTable( $name, $patch, $fullpath = false ) {
                if ( $this->db->tableExists( $name ) ) {
-                       wfOut( "...$name table already exists.\n" );
+                       $this->output( "...$name table already exists.\n" );
                } else {
-                       wfOut( "Creating $name table..." );
+                       $this->output( "Creating $name table..." );
                        $this->applyPatch( $patch, $fullpath );
-                       wfOut( "ok\n" );
+                       $this->output( "ok\n" );
                }
        }
 
@@ -289,13 +314,13 @@ abstract class DatabaseUpdater {
         */
        protected function addField( $table, $field, $patch, $fullpath = false ) {
                if ( !$this->db->tableExists( $table ) ) {
-                       wfOut( "...$table table does not exist, skipping new field patch\n" );
+                       $this->output( "...$table table does not exist, skipping new field patch\n" );
                } elseif ( $this->db->fieldExists( $table, $field ) ) {
-                       wfOut( "...have $field field in $table table.\n" );
+                       $this->output( "...have $field field in $table table.\n" );
                } else {
-                       wfOut( "Adding $field field to table $table..." );
+                       $this->output( "Adding $field field to table $table..." );
                        $this->applyPatch( $patch, $fullpath );
-                       wfOut( "ok\n" );
+                       $this->output( "ok\n" );
                }
        }
 
@@ -308,11 +333,11 @@ abstract class DatabaseUpdater {
         */
        function addIndex( $table, $index, $patch, $fullpath = false ) {
                if ( $this->db->indexExists( $table, $index ) ) {
-                       wfOut( "...$index key already set on $table table.\n" );
+                       $this->output( "...$index key already set on $table table.\n" );
                } else {
-                       wfOut( "Adding $index key to table $table... " );
+                       $this->output( "Adding $index key to table $table... " );
                        $this->applyPatch( $patch, $fullpath );
-                       wfOut( "ok\n" );
+                       $this->output( "ok\n" );
                }
        }
 
@@ -326,11 +351,11 @@ abstract class DatabaseUpdater {
         */
        function dropField( $table, $field, $patch, $fullpath = false ) {
                if ( $this->db->fieldExists( $table, $field ) ) {
-                       wfOut( "Table $table contains $field field. Dropping... " );
+                       $this->output( "Table $table contains $field field. Dropping... " );
                        $this->applyPatch( $patch, $fullpath );
-                       wfOut( "ok\n" );
+                       $this->output( "ok\n" );
                } else {
-                       wfOut( "...$table table does not contain $field field.\n" );
+                       $this->output( "...$table table does not contain $field field.\n" );
                }
        }
 
@@ -344,11 +369,11 @@ abstract class DatabaseUpdater {
         */
        function dropIndex( $table, $index, $patch, $fullpath = false ) {
                if ( $this->db->indexExists( $table, $index ) ) {
-                       wfOut( "Dropping $index from table $table... " );
+                       $this->output( "Dropping $index from table $table... " );
                        $this->applyPatch( $patch, $fullpath );
-                       wfOut( "ok\n" );
+                       $this->output( "ok\n" );
                } else {
-                       wfOut( "...$index key doesn't exist.\n" );
+                       $this->output( "...$index key doesn't exist.\n" );
                }
        }
 
@@ -362,13 +387,13 @@ abstract class DatabaseUpdater {
         */
        public function modifyField( $table, $field, $patch, $fullpath = false ) {
                if ( !$this->db->tableExists( $table ) ) {
-                       wfOut( "...$table table does not exist, skipping modify field patch\n" );
+                       $this->output( "...$table table does not exist, skipping modify field patch\n" );
                } elseif ( !$this->db->fieldExists( $table, $field ) ) {
-                       wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
+                       $this->output( "...$field field does not exist in $table table, skipping modify field patch\n" );
                } else {
-                       wfOut( "Modifying $field field of table $table..." );
+                       $this->output( "Modifying $field field of table $table..." );
                        $this->applyPatch( $patch, $fullpath );
-                       wfOut( "ok\n" );
+                       $this->output( "ok\n" );
                }
        }
 
@@ -378,23 +403,23 @@ abstract class DatabaseUpdater {
        protected function purgeCache() {
                # We can't guarantee that the user will be able to use TRUNCATE,
                # but we know that DELETE is available to us
-               wfOut( "Purging caches..." );
+               $this->output( "Purging caches..." );
                $this->db->delete( 'objectcache', '*', __METHOD__ );
-               wfOut( "done.\n" );
+               $this->output( "done.\n" );
        }
 
        /**
         * Check the site_stats table is not properly populated.
         */
        protected function checkStats() {
-               wfOut( "Checking site_stats row..." );
+               $this->output( "Checking site_stats row..." );
                $row = $this->db->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
                if ( $row === false ) {
-                       wfOut( "data is missing! rebuilding...\n" );
+                       $this->output( "data is missing! rebuilding...\n" );
                } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
-                       wfOut( "missing ss_total_pages, rebuilding...\n" );
+                       $this->output( "missing ss_total_pages, rebuilding...\n" );
                } else {
-                       wfOut( "done.\n" );
+                       $this->output( "done.\n" );
                        return;
                }
                SiteStatsInit::doAllAndCommit( false );
@@ -414,33 +439,33 @@ abstract class DatabaseUpdater {
                                array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
                        );
                }
-               wfOut( "...ss_active_users user count set...\n" );
+               $this->output( "...ss_active_users user count set...\n" );
        }
 
        protected function doLogSearchPopulation() {
                if ( $this->updateRowExists( 'populate log_search' ) ) {
-                       wfOut( "...log_search table already populated.\n" );
+                       $this->output( "...log_search table already populated.\n" );
                        return;
                }
 
-               wfOut(
+               $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 = new PopulateLogSearch();
                $task->execute();
-               wfOut( "Done populating log_search table.\n" );
+               $this->output( "Done populating log_search table.\n" );
        }
 
        function doUpdateTranscacheField() {
                if ( $this->updateRowExists( 'convert transcache field' ) ) {
-                       wfOut( "...transcache tc_time already converted.\n" );
+                       $this->output( "...transcache tc_time already converted.\n" );
                        return;
                }
 
-               wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
+               $this->output( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
                $this->applyPatch( 'patch-tc-timestamp.sql' );
-               wfOut( "ok\n" );
+               $this->output( "ok\n" );
        }
 
        protected function doCollationUpdate() {
@@ -451,7 +476,7 @@ abstract class DatabaseUpdater {
                        'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
                        __METHOD__
                ) == 0 ) {
-                       wfOut( "...collations up-to-date.\n" );
+                       $this->output( "...collations up-to-date.\n" );
                        return;
                }