* make canCreateAccounts() return Status Objects instead of boolean
authorMark A. Hershberger <mah@users.mediawiki.org>
Fri, 4 Feb 2011 00:15:44 +0000 (00:15 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Fri, 4 Feb 2011 00:15:44 +0000 (00:15 +0000)
* re-use openConnection to test the ability of the user to connect.

includes/installer/PostgresInstaller.php

index 4a153ec..311e7d2 100644 (file)
@@ -137,15 +137,11 @@ class PostgresInstaller extends DatabaseInstaller {
                        array( 'usename' => $superuser ), __METHOD__
                );
 
-               if( !$rights ) {
-                       return false;
-               }
-
-               if( $rights != 1 && $rights != 3 ) {
-                       return false;
+               if( !$rights || ( $rights != 1 && $rights != 3 ) ) {
+                       $status = Status::newFatal("can't create");
                }
 
-               return true;
+               return $status;
        }
 
        public function getSettingsForm() {
@@ -166,26 +162,21 @@ class PostgresInstaller extends DatabaseInstaller {
                }
 
                // Validate the create checkbox
+               $create = true;
                $canCreate = $this->canCreateAccounts();
-               if ( !$canCreate ) {
+               if ( !$canCreate->isOK() ) {
                        $this->setVar( '_CreateDBAccount', false );
                        $create = false;
                } else {
                        $create = $this->getVar( '_CreateDBAccount' );
                }
 
-               if ( !$create ) {
+               // Don't test the web account if it is the same as the admin.
+               if ( !$create && $this->getVar( 'wgDBuser' ) != $this->getVar( '_InstallUser' ) ) {
                        // Test the web account
                        try {
-                               new DatabasePostgres(
-                                       $this->getVar( 'wgDBserver' ),
-                                       $this->getVar( 'wgDBuser' ),
-                                       $this->getVar( 'wgDBpassword' ),
-                                       false,
-                                       false,
-                                       0,
-                                       $this->getVar( 'wgDBprefix' )
-                               );
+                               $this->useAdmin = FALSE;
+                               return $this->openConnection();
                        } catch ( DBConnectionError $e ) {
                                return Status::newFatal( 'config-connection-error', $e->getMessage() );
                        }