* removed DEFAULT '' NOT NULL constraints as '' is internaly converted to NULL in...
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index fa4d74a..c519087 100644 (file)
@@ -30,12 +30,6 @@ abstract class DatabaseUpdater {
         */
        protected $extensionUpdates = array();
 
-       /**
-        * Used to hold schema files during installation process
-        * @var array
-        */
-       protected $newExtensions = array();
-
        /**
         * Handle to the database subclass
         *
@@ -65,7 +59,9 @@ abstract class DatabaseUpdater {
                } else {
                        $this->maintenance = new FakeMaintenance;
                }
+               $this->maintenance->setDB( $db );
                $this->initOldGlobals();
+               $this->loadExtensions();
                wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) );
        }
 
@@ -87,6 +83,25 @@ abstract class DatabaseUpdater {
                $wgExtModifiedFields = array(); // table, index, dir
        }
 
+       /**
+        * Loads LocalSettings.php, if needed, and initialises everything needed for LoadExtensionSchemaUpdates hook
+        */
+       private function loadExtensions() {
+               if ( !defined( 'MEDIAWIKI_INSTALL' ) ) {
+                       return; // already loaded
+               }
+               $vars = Installer::getExistingLocalSettings();
+               if ( !$vars ) {
+                       return; // no LocalSettings found
+               }
+               if ( !isset( $vars['wgHooks'] ) || !isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
+                       return;
+               }
+               global $wgHooks, $wgAutoloadClasses;
+               $wgHooks['LoadExtensionSchemaUpdates'] = $vars['wgHooks']['LoadExtensionSchemaUpdates'];
+               $wgAutoloadClasses = $wgAutoloadClasses + $vars['wgAutoloadClasses'];
+       }
+
        /**
         * @throws MWException
         * @param DatabaseBase $db
@@ -155,23 +170,6 @@ abstract class DatabaseUpdater {
                $this->extensionUpdates[] = array( 'addTable', $tableName, $sqlPath, true );
        }
 
-       /**
-        * Add a brand new extension to MediaWiki. Used during the initial install
-        * @param $ext String Name of extension
-        * @param $sqlPath String Full path to the schema file
-        */
-       public function addNewExtension( $ext, $sqlPath ) {
-               $this->newExtensions[ strtolower( $ext ) ] = $sqlPath;
-       }
-
-       /**
-        * Get the list of extensions that registered a schema with our DB type
-        * @return array
-        */
-       public function getNewExtensions() {
-               return $this->newExtensions;
-       }
-
        /**
         * Get the list of extension-defined updates
         *
@@ -191,6 +189,7 @@ abstract class DatabaseUpdater {
         * @param $what Array: what updates to perform
         */
        public function doUpdates( $what = array( 'core', 'extensions', 'purge' ) ) {
+               global $wgVersion;
 
                $what = array_flip( $what );
                if ( isset( $what['core'] ) ) {
@@ -201,7 +200,7 @@ abstract class DatabaseUpdater {
                        $this->runUpdates( $this->getExtensionUpdates(), true );
                }
 
-               $this->setAppliedUpdates( MW_VERSION, $this->updates );
+               $this->setAppliedUpdates( $wgVersion, $this->updates );
 
                if( isset( $what['purge'] ) ) {
                        $this->purgeCache();
@@ -233,6 +232,7 @@ abstract class DatabaseUpdater {
        }
 
        protected function setAppliedUpdates( $version, $updates = array() ) {
+               $this->db->clearFlag( DBO_DDLMODE );
                if( !$this->canUseNewUpdatelog() ) {
                        return;
                }
@@ -240,6 +240,7 @@ abstract class DatabaseUpdater {
                $this->db->insert( 'updatelog',
                        array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
                         __METHOD__ );
+               $this->db->setFlag( DBO_DDLMODE );
        }
 
        /**
@@ -266,11 +267,13 @@ abstract class DatabaseUpdater {
         * @param $val String [optional] value to insert along with the key
         */
        public function insertUpdateRow( $key, $val = null ) {
+               $this->db->clearFlag( DBO_DDLMODE );
                $values = array( 'ul_key' => $key );
                if( $val && $this->canUseNewUpdatelog() ) {
                        $values['ul_value'] = $val;
                }
                $this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' );
+               $this->db->setFlag( DBO_DDLMODE );
        }
 
        /**