new-installer: Delay database object construction until ->execute time
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Tue, 6 Jul 2010 20:40:05 +0000 (20:40 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Tue, 6 Jul 2010 20:40:05 +0000 (20:40 +0000)
My method of putting code that alters $this->parent->installSteps in
the MySQL constructor didn't work because the installer will construct
objects for all the databases, even those it doesn't use.

This ostensibly happens because it needs to be able to provide
defaults for all of them on the DBConnect page.

But when I was going to fix that by exiting the MySQL constructior by
checking $wgDBtype I found that it didn't work, because WebInstaller
calls Installer's __construct *before* any sessions are read or set
up, so $wgDBtype will always be mysql, since that's the default.

Fix that by delaying the construction of the database objects. The
WebInstaller (or equivalent) now has to call ->setupDatabaseObjects()
in its ->execute method. This way the defaults on the DBConnect will
still be provided, but we'll have access to session data in the
database constructors.

Ughed-by: Chad <innocentkiller@gmail.com>
includes/installer/Installer.php
includes/installer/MysqlInstaller.php
includes/installer/WebInstaller.php

index 354daf8..4124028 100644 (file)
@@ -233,6 +233,18 @@ abstract class Installer {
                foreach ( $this->defaultVarNames as $var ) {
                        $this->settings[$var] = $GLOBALS[$var];
                }
+
+               $this->parserTitle = Title::newFromText( 'Installer' );
+               $this->parserOptions = new ParserOptions;
+               $this->parserOptions->setEditSection( false );
+       }
+
+       /*
+        * Set up our database objects. They need to inject some of their
+        * own configuration into our global context. Usually this'll just be
+        * things like the default $wgDBname.
+        */
+       function setupDatabaseObjects() {
                foreach ( $this->dbTypes as $type ) {
                        $installer = $this->getDBInstaller( $type );
                        if ( !$installer->isCompiled() ) {
@@ -247,10 +259,6 @@ abstract class Installer {
                                }
                        }
                }
-
-               $this->parserTitle = Title::newFromText( 'Installer' );
-               $this->parserOptions = new ParserOptions;
-               $this->parserOptions->setEditSection( false );
        }
 
        /**
index 1951f9b..26c3899 100644 (file)
@@ -35,6 +35,10 @@ class MysqlInstaller extends InstallerDBType {
        function __construct( $parent ) {
                parent::__construct( $parent );
 
+               if ( $this->parent->getVar( 'wgDBtype' ) !== $this->getName() ) {
+                       return;
+               }
+
                # Add our user callback to installSteps, right before the tables are created.
                $where_tables = array_search( "tables", $this->parent->installSteps );
                $callback = array(
index ca81a35..c5bc3dd 100644 (file)
@@ -81,6 +81,10 @@ class WebInstaller extends Installer {
                if ( isset( $session['settings'] ) ) {
                        $this->settings = $session['settings'] + $this->settings;
                }
+
+               /* Must be called after the session setup above */
+               $this->setupDatabaseObjects();
+
                $this->exportVars();
                $this->setupLanguage();