The beginnings of HipHop compiled mode support. It works now for parser cache hits.
[lhc/web/wiklou.git] / includes / installer / PostgresInstaller.php
index f73350e..c237a11 100644 (file)
@@ -35,6 +35,11 @@ class PostgresInstaller extends DatabaseInstaller {
        }
 
        function getConnectForm() {
+               // If this is our first time here, switch the default user presented in the form
+               if ( ! $this->getVar('_switchedInstallUser') ) {
+                       $this->setVar('_InstallUser', 'postgres');
+                       $this->setVar('_switchedInstallUser', true);
+               }
                return
                        $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent->getHelpBox( 'config-db-host-help' ) ) .
                        $this->getTextBox( 'wgDBport', 'config-db-port' ) .
@@ -104,7 +109,7 @@ class PostgresInstaller extends DatabaseInstaller {
                                        $this->getVar( 'wgDBserver' ),
                                        $this->getVar( '_InstallUser' ),
                                        $this->getVar( '_InstallPassword' ),
-                                       'template1' );
+                                       'postgres' );
                        } else {
                                $db = new DatabasePostgres(
                                        $this->getVar( 'wgDBserver' ),
@@ -162,9 +167,7 @@ class PostgresInstaller extends DatabaseInstaller {
                }
 
                // Validate the create checkbox
-               $create = true;
-               $canCreate = $this->canCreateAccounts();
-               if ( $canCreate ) {
+               if ( !$this->canCreateAccounts() ) {
                        $this->setVar( '_CreateDBAccount', false );
                        $create = false;
                } else {
@@ -190,17 +193,18 @@ class PostgresInstaller extends DatabaseInstaller {
                        'name' => 'pg-commit',
                        'callback' => array( $this, 'commitChanges' ),
                );
-               $userCB = array(
-                       'name' => 'user',
-                       'callback' => array( $this, 'setupUser' ),
-               );
                $plpgCB = array(
                        'name' => 'pg-plpgsql',
                        'callback' => array( $this, 'setupPLpgSQL' ),
                );
                $this->parent->addInstallStep( $commitCB, 'interwiki' );
-               $this->parent->addInstallStep( $userCB );
                $this->parent->addInstallStep( $plpgCB, 'database' );
+               if( $this->getVar( '_CreateDBAccount' ) ) {
+                       $this->parent->addInstallStep( array(
+                               'name' => 'user',
+                               'callback' => array( $this, 'setupUser' ),
+                       ) );
+               }
        }
 
        function setupDatabase() {
@@ -213,46 +217,48 @@ class PostgresInstaller extends DatabaseInstaller {
                $conn = $status->value;
 
                $dbName = $this->getVar( 'wgDBname' );
+               $schema = $this->getVar( 'wgDBmwschema' );
+               $user = $this->getVar( 'wgDBuser' );
+               $safeschema = $conn->addIdentifierQuotes( $schema );
+               $safeuser = $conn->addIdentifierQuotes( $user );
+
                $SQL = "SELECT 1 FROM pg_catalog.pg_database WHERE datname = " . $conn->addQuotes( $dbName );
                $rows = $conn->numRows( $conn->query( $SQL ) );
+               $safedb = $conn->addIdentifierQuotes( $dbName );
                if( !$rows ) {
-                       $schema = $this->getVar( 'wgDBmwschema' );
-                       $user = $this->getVar( 'wgDBuser' );
-
-                       $safeschema = $conn->addIdentifierQuotes( $schema );
-                       $safeuser = $conn->addIdentifierQuotes( $user );
-
-                       $safedb = $conn->addIdentifierQuotes( $dbName );
-
                        $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ );
+               } else {
+                       $conn->query( "ALTER DATABASE $safedb OWNER TO $safeuser", __METHOD__ );
+               }
+               
+               // Now that we've established the real database exists, connect to it
+               // Because we do not want the same connection, forcibly expire the existing conn
+               $this->db = null;
+               $this->useAdmin = false;
+               $status = $this->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+               $conn = $status->value;
 
-                       $this->useAdmin = false;
-                       $status = $this->getConnection();
-                       if ( !$status->isOK() ) {
-                               return $status;
-                       }
-                       $conn = $status->value;
-
-                       $result = $conn->schemaExists( $schema );
+               if( !$conn->schemaExists( $schema ) ) {
+                       $result = $conn->query( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
                        if( !$result ) {
-                               $result = $conn->query( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
-                               if( !$result ) {
-                                       $status->fatal( 'config-install-pg-schema-failed', $user, $schema );
-                               }
-                       } else {
-                               $safeschema2 = $conn->addQuotes( $schema );
-                               $SQL = "SELECT 'GRANT ALL ON '||pg_catalog.quote_ident(relname)||' TO $safeuser;'\n".
-                                       "FROM pg_catalog.pg_class p, pg_catalog.pg_namespace n\n" .
-                                       "WHERE relnamespace = n.oid AND n.nspname = $safeschema2\n" .
-                                       "AND p.relkind IN ('r','S','v')\n";
-                               $SQL .= "UNION\n";
-                               $SQL .= "SELECT 'GRANT ALL ON FUNCTION '||pg_catalog.quote_ident(proname)||'('||\n".
-                                       "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 );
+                               $status->fatal( 'config-install-pg-schema-failed', $user, $schema );
                        }
+               } else {
+                       $safeschema2 = $conn->addQuotes( $schema );
+                       $SQL = "SELECT 'GRANT ALL ON '||pg_catalog.quote_ident(relname)||' TO $safeuser;'\n".
+                               "FROM pg_catalog.pg_class p, pg_catalog.pg_namespace n\n" .
+                               "WHERE relnamespace = n.oid AND n.nspname = $safeschema2\n" .
+                               "AND p.relkind IN ('r','S','v')\n";
+                       $SQL .= "UNION\n";
+                       $SQL .= "SELECT 'GRANT ALL ON FUNCTION '||pg_catalog.quote_ident(proname)||'('||\n".
+                               "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 );
                }
                return $status;
        }
@@ -274,7 +280,6 @@ class PostgresInstaller extends DatabaseInstaller {
                        return $status;
                }
 
-               $db = $this->getVar( 'wgDBname' );
                $schema = $this->getVar( 'wgDBmwschema' );
                $safeuser = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) );
                $safeusercheck = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
@@ -289,7 +294,9 @@ class PostgresInstaller extends DatabaseInstaller {
                        if ( $res !== true && !( $res instanceOf ResultWrapper ) ) {
                                $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res );
                        }
-                       $this->db->query("ALTER USER $safeuser SET search_path = $safeschema");
+                       if( $status->isOK() ) {
+                               $this->db->query("ALTER USER $safeuser SET search_path = $safeschema");
+                       }
                }
 
                return $status;
@@ -315,7 +322,6 @@ class PostgresInstaller extends DatabaseInstaller {
 
        public function createTables() {
                $schema = $this->getVar( 'wgDBmwschema' );
-               $user = $this->getVar( 'wgDBuser' );
 
                $this->db = null;
                $this->useAdmin = false;
@@ -323,17 +329,14 @@ class PostgresInstaller extends DatabaseInstaller {
                if ( !$status->isOK() ) {
                        return $status;
                }
-               $this->db->selectDB( $this->getVar( 'wgDBname' ) );
 
                if( $this->db->tableExists( 'user' ) ) {
                        $status->warning( 'config-install-tables-exist' );
                        return $status;
                }
 
-               $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;