From ec4c20458ec11cf99ab29793d79e93f23162b073 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Mon, 4 Feb 2008 16:40:35 +0000 Subject: [PATCH] Refactor Pl/Pgsql check so we can also attempt installing when connecting as superuser. --- includes/DatabasePostgres.php | 60 ++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index 48c99dbd8c..47d10ae189 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -335,6 +335,9 @@ class DatabasePostgres extends Database { print "OK"; } + ## Install plpgsql if needed + $this->setup_plpgsql(); + $wgDBsuperuser = ''; return true; // Reconnect as regular user @@ -415,32 +418,8 @@ class DatabasePostgres extends Database { } print "OK"; - ## Do we have plpgsql installed? - print "
  • Checking for Pl/Pgsql ..."; - $SQL = "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'"; - $rows = $this->numRows($this->doQuery($SQL)); - if ($rows < 1) { - // plpgsql is not installed, but if we have a pg_pltemplate table, we should be able to create it - print "not installed. Attempting to install Pl/Pgsql ..."; - $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ". - "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'"; - $rows = $this->numRows($this->doQuery($SQL)); - if ($rows >= 1) { - $olde = error_reporting(0); - error_reporting($olde - E_WARNING); - $result = $this->doQuery("CREATE LANGUAGE plpgsql"); - error_reporting($olde); - if (!$result) { - print "FAILED. You need to install the language plpgsql in the database $wgDBname
  • "; - dieout(""); - } - } - else { - print "FAILED. You need to install the language plpgsql in the database $wgDBname"; - dieout(""); - } - } - print "OK\n"; + ## Install plpgsql if needed + $this->setup_plpgsql(); ## Does the schema already exist? Who owns it? $result = $this->schemaExists($wgDBmwschema); @@ -524,6 +503,35 @@ class DatabasePostgres extends Database { } + function setup_plpgsql() { + print "
  • Checking for Pl/Pgsql ..."; + $SQL = "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'"; + $rows = $this->numRows($this->doQuery($SQL)); + if ($rows < 1) { + // plpgsql is not installed, but if we have a pg_pltemplate table, we should be able to create it + print "not installed. Attempting to install Pl/Pgsql ..."; + $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ". + "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'"; + $rows = $this->numRows($this->doQuery($SQL)); + if ($rows >= 1) { + $olde = error_reporting(0); + error_reporting($olde - E_WARNING); + $result = $this->doQuery("CREATE LANGUAGE plpgsql"); + error_reporting($olde); + if (!$result) { + print "FAILED. You need to install the language plpgsql in the database $wgDBname
  • "; + dieout(""); + } + } + else { + print "FAILED. You need to install the language plpgsql in the database $wgDBname"; + dieout(""); + } + } + print "OK\n"; + } + + /** * Closes a database connection, if it is open * Returns success, true if already closed -- 2.20.1