Make schema selection really work for PostgreSQL installation
authorMark A. Hershberger <mah@users.mediawiki.org>
Sun, 6 Feb 2011 03:06:45 +0000 (03:06 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sun, 6 Feb 2011 03:06:45 +0000 (03:06 +0000)
includes/db/DatabasePostgres.php
includes/installer/Installer.i18n.php
includes/installer/PostgresInstaller.php

index 9fbd85e..17304f8 100644 (file)
@@ -195,7 +195,6 @@ class DatabasePostgres extends DatabaseBase {
 
                global $wgDBmwschema;
                if ( isset( $wgDBmwschema )
-                       && $wgDBmwschema !== 'mediawiki'
                        && preg_match( '/^\w+$/', $wgDBmwschema )
                ) {
                        $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
index ae69340..d1a6bfd 100644 (file)
@@ -444,6 +444,7 @@ If you still want to make changes, press back.',
        'config-install-step-failed'      => 'failed',
        'config-install-extensions'       => 'Including extensions',
        'config-install-database'         => 'Setting up database',
+       'config-install-pg-schema-not-exist' => 'PostgreSQL schema does not exist',
        'config-install-pg-schema-failed' => 'Tables creation failed.
 Make sure that the user "$1" can write to the schema "$2".',
        'config-install-pg-commit'        => 'Committing changes',
index 597b66b..f73350e 100644 (file)
@@ -226,15 +226,12 @@ class PostgresInstaller extends DatabaseInstaller {
 
                        $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ );
 
-                       $conn = new DatabasePostgres(
-                               $this->getVar( 'wgDBserver' ),
-                               $this->getVar( 'wgDBuser' ),
-                               $this->getVar( 'wgDBpassword' ),
-                               $dbName,
-                               false,
-                               0,
-                               $this->getVar( 'wgDBprefix' )
-                       );
+                       $this->useAdmin = false;
+                       $status = $this->getConnection();
+                       if ( !$status->isOK() ) {
+                               return $status;
+                       }
+                       $conn = $status->value;
 
                        $result = $conn->schemaExists( $schema );
                        if( !$result ) {
@@ -253,6 +250,7 @@ class PostgresInstaller extends DatabaseInstaller {
                                        "pg_catalog.oidvectortypes(p.proargtypes)||') TO $safeuser;'\n" .
                                        "FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n\n" .
                                        "WHERE p.pronamespace = n.oid AND n.nspname = $safeschema2";
+                               $conn->query( "SET search_path = $safeschema" );
                                $res = $conn->query( $SQL );
                        }
                }
@@ -316,6 +314,9 @@ class PostgresInstaller extends DatabaseInstaller {
        }
 
        public function createTables() {
+               $schema = $this->getVar( 'wgDBmwschema' );
+               $user = $this->getVar( 'wgDBuser' );
+
                $this->db = null;
                $this->useAdmin = false;
                $status = $this->getConnection();
@@ -332,6 +333,13 @@ class PostgresInstaller extends DatabaseInstaller {
                $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
                $this->db->begin( __METHOD__ );
 
+
+               if( !$this->db->schemaExists( $schema ) ) {
+                       $status->error( 'config-install-pg-schema-not-exist' );
+                       return $status;
+               }
+               $safeschema = $this->db->addIdentifierQuotes( $schema );
+               $this->db->query( "SET search_path = $safeschema" );
                $error = $this->db->sourceFile( $this->db->getSchema() );
                if( $error !== true ) {
                        $this->db->reportQueryError( $error, 0, '', __METHOD__ );