[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3157] trunk/LedgerSMB/Initiate.pm



Revision: 3157
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3157&view=rev
Author:   einhverfr
Date:     2011-05-22 20:47:10 +0000 (Sun, 22 May 2011)

Log Message:
-----------
applying Ian Goodacre's patch 2945454, to Initiate.pm

Modified Paths:
--------------
    trunk/LedgerSMB/Initiate.pm

Modified: trunk/LedgerSMB/Initiate.pm
===================================================================
--- trunk/LedgerSMB/Initiate.pm	2011-05-22 20:19:44 UTC (rev 3156)
+++ trunk/LedgerSMB/Initiate.pm	2011-05-22 20:47:10 UTC (rev 3157)
@@ -253,9 +253,33 @@
 
 		# Now all the files are found now start execution process(Stages)
 
+    # Initial setup operations are performed while connected to the postgres
+    # database as the currently authenticated user. This database should be
+    # present even on a fresh install of PostgreSQL. The authenticated user
+    # must have superuser rights to complete this stage of the setup.
+    $form->{dbh} = DBI->connect(
+        "dbi:Pg:db=postgres;host=$form->{dbhost};port=$form->{dbport}",
+        $form->{username},
+        $form->{password},
+    ) or $form->error( __FILE__ . ':' . __LINE__ . ': ' .
+        $locale->text( 'unable to connect to postgres database on [_1]:[_2]',
+            $form->{dbhost},$form->{dbport}));
+
 		#Stage 1 -   Create the databse $form->{database}
 
-	LedgerSMB::Initiate->create_database($form,$form->{dbh},$form->{database},$form->{username}); 
+    # Initial setup operations are performed while connected to the postgres
+    # database as the currently authenticated user. This database should be
+    # present even on a fresh install of PostgreSQL. The authenticated user
+    # must have superuser rights to complete this stage of the setup.
+    $form->{dbh} = DBI->connect(
+        "dbi:Pg:db=postgres;host=$form->{dbhost};port=$form->{dbport}",
+        $form->{username},
+        $form->{password},
+    ) or $form->error( __FILE__ . ':' . __LINE__ . ': ' .
+        $locale->text( 'unable to connect to postgres database on [_1]:[_2]',
+            $form->{dbhost},$form->{dbport}));
+
+	LedgerSMB::Initiate->create_database($form); 
 		
 		#Stage 2 -  CReate the language plpgsql
 	
@@ -341,17 +365,24 @@
 
 sub create_database
 {
+    my ($self,$form)..hidden..;
 
+    # Create the admin user first, so it can be the owner of the new database
+	if ($form->{createuser}){
+        # Note: LedgerSMB setup for this user is done in process_roles()
+		$form->{dbh}->do(
+            "CREATE ROLE " . 
+			$form->{dbh}->quote_identifier($form->{admin_username}) .
+            " WITH CREATEROLE " .
+			" WITH PASSWORD " .  $dbh->quote($form->{admin_password}) .
+            ";\n"
+        );
+    }
 
-	my ($self,$form,$dbh,$database,$owner)..hidden..;
-
-	my $locale=$form->{locale};
-
-	$dbh->do("create database $database with owner $owner") || $form->error( __FILE__ . ':' . __LINE__ . ': '
-                  . $locale->text( 'database [_1] creation failed',$database));
-
-	
-
+    $form->{dbh}->do(
+        "create database $form->{database} with owner $form->{username}"
+    ) || $form->error( __FILE__ . ':' . __LINE__ . ': '
+            . $locale->text( 'database [_1] creation failed',$database));
 }
 
 sub handle_create_language


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.