Move setup_plpgsql() to PostgresInstaller and make it use status objects for when...
authorChad Horohoe <demon@users.mediawiki.org>
Mon, 27 Dec 2010 15:41:11 +0000 (15:41 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Mon, 27 Dec 2010 15:41:11 +0000 (15:41 +0000)
includes/db/DatabasePostgres.php
includes/installer/Installer.i18n.php
includes/installer/PostgresInstaller.php

index dff73e9..86492b0 100644 (file)
@@ -537,36 +537,6 @@ class DatabasePostgres extends DatabaseBase {
                }
        }
 
-       function setup_plpgsql() {
-               print '<li>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 ) );
-                       global $wgDBname;
-                       if ( $rows >= 1 ) {
-                               $olde = error_reporting( 0 );
-                               error_reporting( $olde - E_WARNING );
-                               $result = $this->doQuery( 'CREATE LANGUAGE plpgsql' );
-                               error_reporting( $olde );
-                               if ( !$result ) {
-                                       print '<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>' .
-                                               htmlspecialchars( $wgDBname ) . '</tt></li>';
-                                       dieout( );
-                               }
-                       } else {
-                               print '<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>' .
-                                       htmlspecialchars( $wgDBname ) . '</tt></li>';
-                               dieout( );
-                       }
-               }
-               print "OK</li>\n";
-       }
-
        /**
         * Closes a database connection, if it is open
         * Returns success, true if already closed
index 1cdfbf8..6ab8d57 100644 (file)
@@ -449,6 +449,7 @@ Please proceed to the next page.",
        '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',
+       'config-pg-no-plpgsql'            => 'You need to install the language PL/pgSQL in the database $1',
        'config-install-user'             => 'Creating database user',
        'config-install-user-failed'      => 'Granting permission to user "$1" failed: $2',
        'config-install-tables'           => 'Creating tables',
index aa9d68b..7f5612b 100644 (file)
@@ -166,4 +166,26 @@ class PostgresInstaller extends DatabaseInstaller {
                $wgDBuser = $this->getVar( '_InstallUser' );
                $wgDBpassword = $this->getVar( '_InstallPassword' );
        }
+
+       private function setupPLpgSQL() {
+               $rows = $this->numRows( 
+                       $this->db->query( "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'" )
+               );
+               if ( $rows < 1 ) {
+                       // plpgsql is not installed, but if we have a pg_pltemplate table, we should be able to create it
+                       $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->db->query( $SQL ) );
+                       global $wgDBname;
+                       if ( $rows >= 1 ) {
+                               $result = $this->db->query( 'CREATE LANGUAGE plpgsql' );
+                               if ( !$result ) {
+                                       return Status::newFatal( 'pg-no-plpgsql', $wgDBname );
+                               }
+                       } else {
+                               return Status::newFatal( 'pg-no-plpgsql', $wgDBname );
+                       }
+               }
+               return Status::newGood();
+       }
 }