From 3ae5637b223669d503edba9687975b84190a14de Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 4 Jul 2010 16:16:28 +0000 Subject: [PATCH] new-installer: GRANT permissions to our new non-root user by sourcing users.sql 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 | 2 ++ includes/installer/Installer.php | 7 +++++++ includes/installer/InstallerDBType.php | 12 ++++++++++++ includes/installer/MysqlInstaller.php | 22 ++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index 2927d1f8b6..8f57e112db 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -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 interwiki.sql', diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 6af820b9db..f99b8deea2 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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(); diff --git a/includes/installer/InstallerDBType.php b/includes/installer/InstallerDBType.php index 9703f4b57d..46269a05d2 100644 --- a/includes/installer/InstallerDBType.php +++ b/includes/installer/InstallerDBType.php @@ -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 diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index f0d6035b8d..a078d1eb96 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -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(); -- 2.20.1