From 4625f338cacae413af67ec918e644e7b167b05fb Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sun, 6 Feb 2011 03:06:45 +0000 Subject: [PATCH] Make schema selection really work for PostgreSQL installation --- includes/db/DatabasePostgres.php | 1 - includes/installer/Installer.i18n.php | 1 + includes/installer/PostgresInstaller.php | 26 ++++++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 9fbd85edb2..17304f8d14 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -195,7 +195,6 @@ class DatabasePostgres extends DatabaseBase { global $wgDBmwschema; if ( isset( $wgDBmwschema ) - && $wgDBmwschema !== 'mediawiki' && preg_match( '/^\w+$/', $wgDBmwschema ) ) { $safeschema = $this->addIdentifierQuotes( $wgDBmwschema ); diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index ae69340305..d1a6bfdf78 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -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', diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 597b66b86b..f73350e96e 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -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__ ); -- 2.20.1