new-installer: GRANT permissions to our new non-root user by sourcing users.sql
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 4 Jul 2010 16:16:28 +0000 (16:16 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 4 Jul 2010 16:16:28 +0000 (16:16 +0000)
The old installer sourced maintenance/users.sql to create a new
non-root user if requested. Do that in the new installer as well.

So far this only works on MySQL, but I'm adding a generic setupUser
function on the assumption that other databases (except SQLite) want
to do some sort of user setup.

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

index 2927d1f..8f57e11 100644 (file)
@@ -419,6 +419,8 @@ They may require additional configuration, but you can enable them now',
        'config-install-database'         => 'Setting up database',
        'config-install-pg-schema-failed' => 'Tables creation failed.
 Make sure that the user "$1" can write to the schema "$2".',
+       'config-install-user'             => 'Creating database user',
+       'config-install-user-failed'      => 'Granting permission to user "$1" failed: $2',
        'config-install-tables'           => 'Creating tables',
        'config-install-interwiki'        => 'Populating default interwiki table',
        'config-install-interwiki-sql'    => 'Could not find file <code>interwiki.sql</code>',
index 6af820b..f99b8de 100644 (file)
@@ -128,6 +128,7 @@ abstract class Installer {
 
        var $installSteps = array(
                'database',
+               'user',
                'tables',
                'interwiki',
                'secretkey',
@@ -870,6 +871,12 @@ abstract class Installer {
                return $status;
        }
 
+       public function installUser() {
+               $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
+               $status = $installer->setupUser();
+               return $status;
+       }
+
        public function installTables() {
                $installer = $this->getDBInstaller();
                $status = $installer->createTables();
index 9703f4b..46269a0 100644 (file)
@@ -85,6 +85,18 @@ 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 f0d6035..a078d1e 100644 (file)
@@ -376,6 +376,28 @@ class MysqlInstaller extends InstallerDBType {
                return $status;
        }
 
+       function setupUser() {
+               global $IP;
+
+               if ( !$this->getVar( '_CreateDBAccount' ) ) {
+                       return;
+               }
+
+               $status = $this->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+
+               $db = $this->getVar( 'wgDBname' );
+               $this->db->selectDB( $db );
+               $error = $this->db->sourceFile( "$IP/maintenance/users.sql" );
+               if ( !$error ) {
+                       $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
+               }
+
+               return $status;
+       }
+
        function createTables() {
                global $IP;
                $status = $this->getConnection();