new-installer: A better implementation of the database user creation added in r69008
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 4 Jul 2010 21:25:16 +0000 (21:25 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 4 Jul 2010 21:25:16 +0000 (21:25 +0000)
Since MysqlInstaller isn't in the same class hierarchy as WebInstaller
the database user functions I added in r69008 messed up the namespace
for non-MySQL, and added redundant user creation messages to
e.g. SQLite, which doesn't even have users.

Instead support either a plain string in $installSteps, or an array
that has callback data that'll be called with call_user_func_array.

The implementation is a bit ad-hoc, we should probably move the magic
in Hooks.php's wfRunHooks to some general library function so we can
use that here, or perhaps just implement these installSteps with
something like:

    $wgHook['Installer::steps'][] = array(...)

And then use wfRunHooks to run all the steps. But in the meantime
this'll do.

This breaks the nascent CliInstaller (indicating that we should do
these calls better), and I haven't added the equivalent functionality
to $envChecks.

includes/installer/Installer.php
includes/installer/InstallerDBType.php
includes/installer/MysqlInstaller.php
includes/installer/WebInstaller.php

index 24da5cc..47637d1 100644 (file)
@@ -128,7 +128,6 @@ abstract class Installer {
 
        var $installSteps = array(
                'database',
-               'user',
                'tables',
                'interwiki',
                'secretkey',
index 46269a0..9703f4b 100644 (file)
@@ -85,18 +85,6 @@ abstract class InstallerDBType {
         */
        abstract function setupDatabase();
 
-       /**
-        * Create a new non-root user for the database and return a Status
-        * object indicating success or failure. A default implementation
-        * that returns a good status is supplied for those databases that
-        * don't need to set up users.
-        *
-        * @return Status
-        */
-       function setupUser() {
-               return Status::newGood();
-       }
-
        /**
         * Create database tables from scratch
         * @return \type Status
index c0829f4..1951f9b 100644 (file)
@@ -31,6 +31,20 @@ class MysqlInstaller extends InstallerDBType {
        function getName() {
                return 'mysql';
        }
+
+       function __construct( $parent ) {
+               parent::__construct( $parent );
+
+               # Add our user callback to installSteps, right before the tables are created.
+               $where_tables = array_search( "tables", $this->parent->installSteps );
+               $callback = array(
+                       array(
+                               'name' => 'user',
+                               'callback' => array( &$this, 'setupUser' ),
+                       )
+               );
+               array_splice( $this->parent->installSteps, $where_tables, 0, $callback );
+       }
        
        function isCompiled() {
                return $this->checkExtension( 'mysql' );
index f5ada78..40057d4 100644 (file)
@@ -1571,10 +1571,22 @@ class WebInstaller_Install extends WebInstallerPage {
                }
                $this->startForm();
                $this->addHTML("<ul>");
-               foreach( $this->parent->getInstallSteps() as $step ) {
+               foreach( $this->parent->getInstallSteps() as $stepObj ) {
+                       $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj;
                        $this->startStage( "config-install-$step" );
-                       $func = 'install' . ucfirst( $step );
-                       $status = $this->parent->{$func}();
+                       $status = null;
+
+                       # Call our working function
+                       if ( is_array( $step ) ) {
+                               # A custom callaback
+                               $callback = $stepObj['callback'];
+                               $status = call_user_func_array( $callback, array() );
+                       } else {
+                               # Boring implicitly named callback
+                               $func = 'install' . ucfirst( $step );
+                               $status = $this->parent->{$func}();
+                       }
+
                        $ok = $status->isGood();
                        if ( !$ok ) {
                                $this->parent->showStatusErrorBox( $status );