From 5d005d431a4a207243dbbbc09b483849771b23bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 6 Jul 2010 20:40:05 +0000 Subject: [PATCH] new-installer: Delay database object construction until ->execute time 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 --- includes/installer/Installer.php | 16 ++++++++++++---- includes/installer/MysqlInstaller.php | 4 ++++ includes/installer/WebInstaller.php | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 354daf8b99..4124028ddd 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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 ); } /** diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 1951f9b359..26c3899f68 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -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( diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index ca81a35fdc..c5bc3dd855 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -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(); -- 2.20.1