r69008 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69007‎ | r69008 | r69009 >
Date:16:16, 4 July 2010
Author:avar
Status:resolved
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)
  • /trunk/phase3/includes/installer/InstallerDBType.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.i18n.php
@@ -419,6 +419,8 @@
420420 'config-install-database' => 'Setting up database',
421421 'config-install-pg-schema-failed' => 'Tables creation failed.
422422 Make sure that the user "$1" can write to the schema "$2".',
 423+ 'config-install-user' => 'Creating database user',
 424+ 'config-install-user-failed' => 'Granting permission to user "$1" failed: $2',
423425 'config-install-tables' => 'Creating tables',
424426 'config-install-interwiki' => 'Populating default interwiki table',
425427 'config-install-interwiki-sql' => 'Could not find file <code>interwiki.sql</code>',
Index: trunk/phase3/includes/installer/Installer.php
@@ -128,6 +128,7 @@
129129
130130 var $installSteps = array(
131131 'database',
 132+ 'user',
132133 'tables',
133134 'interwiki',
134135 'secretkey',
@@ -870,6 +871,12 @@
871872 return $status;
872873 }
873874
 875+ public function installUser() {
 876+ $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
 877+ $status = $installer->setupUser();
 878+ return $status;
 879+ }
 880+
874881 public function installTables() {
875882 $installer = $this->getDBInstaller();
876883 $status = $installer->createTables();
Index: trunk/phase3/includes/installer/MysqlInstaller.php
@@ -376,6 +376,28 @@
377377 return $status;
378378 }
379379
 380+ function setupUser() {
 381+ global $IP;
 382+
 383+ if ( !$this->getVar( '_CreateDBAccount' ) ) {
 384+ return;
 385+ }
 386+
 387+ $status = $this->getConnection();
 388+ if ( !$status->isOK() ) {
 389+ return $status;
 390+ }
 391+
 392+ $db = $this->getVar( 'wgDBname' );
 393+ $this->db->selectDB( $db );
 394+ $error = $this->db->sourceFile( "$IP/maintenance/users.sql" );
 395+ if ( !$error ) {
 396+ $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
 397+ }
 398+
 399+ return $status;
 400+ }
 401+
380402 function createTables() {
381403 global $IP;
382404 $status = $this->getConnection();
Index: trunk/phase3/includes/installer/InstallerDBType.php
@@ -86,6 +86,18 @@
8787 abstract function setupDatabase();
8888
8989 /**
 90+ * Create a new non-root user for the database and return a Status
 91+ * object indicating success or failure. A default implementation
 92+ * that returns a good status is supplied for those databases that
 93+ * don't need to set up users.
 94+ *
 95+ * @return Status
 96+ */
 97+ function setupUser() {
 98+ return Status::newGood();
 99+ }
 100+
 101+ /**
90102 * Create database tables from scratch
91103 * @return \type Status
92104 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r69020new-installer: A better implementation of the database user creation added in...avar21:25, 4 July 2010

Status & tagging log