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

SF.net SVN: ledger-smb:[4627] trunk



Revision: 4627
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4627&view=rev
Author:   einhverfr
Date:     2012-03-29 01:25:11 +0000 (Thu, 29 Mar 2012)
Log Message:
-----------
Adding centralized db commits when sending HTTP output

Modified Paths:
--------------
    trunk/LedgerSMB/App_State.pm
    trunk/LedgerSMB/Template.pm
    trunk/LedgerSMB.pm

Modified: trunk/LedgerSMB/App_State.pm
===================================================================
--- trunk/LedgerSMB/App_State.pm	2012-03-28 13:36:42 UTC (rev 4626)
+++ trunk/LedgerSMB/App_State.pm	2012-03-29 01:25:11 UTC (rev 4627)
@@ -55,6 +55,14 @@
 
 Hashref for storing connection-specific settings for the application.
 
+=item DBH
+
+Database handle for current connection
+
+=cut
+
+our $DBH;
+
 =back
 
 =head1 METHODS 
@@ -84,6 +92,7 @@
     $SODA = undef;
     $User = undef;
     $Locale = undef;
+    $DBH = undef;
 }
 
 =item cleanup
@@ -94,14 +103,17 @@
 
 sub cleanup {
 
-    $SODA->dbh->disconnect;
-
+    if ($DBH){
+        $DBH->commit;
+        $DBH->disconnect;
+    }
     $Locale           = LedgerSMB::Locale->get_handle(
                             $LedgerSMB::Sysconfig::language
                         );
     $User             = {};
     $SODA             = {};
     $Company_Settings = {};
+    $DBH = undef;
 }
 
 1;

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2012-03-28 13:36:42 UTC (rev 4626)
+++ trunk/LedgerSMB/Template.pm	2012-03-29 01:25:11 UTC (rev 4627)
@@ -333,6 +333,7 @@
 
 sub _http_output {
 	my ($self, $data) = @_;
+        LedgerSMB::App_State::cleanup();
 	$data ||= $self->{output};
 	if ($self->{format} !~ /^\p{IsAlnum}+$/) {
 		throw Error::Simple "Invalid format";
@@ -371,6 +372,7 @@
 
 sub _http_output_file {
 	my $self = shift;
+        LedgerSMB::App_State::cleanup();
 	my $FH;
 
 	open($FH, '<:bytes', $self->{rendered}) or

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2012-03-28 13:36:42 UTC (rev 4626)
+++ trunk/LedgerSMB.pm	2012-03-29 01:25:11 UTC (rev 4627)
@@ -208,6 +208,7 @@
 use LedgerSMB::Sysconfig;
 use Data::Dumper;
 use Error;
+use LedgerSMB::App_State;
 use LedgerSMB::Auth;
 use LedgerSMB::Session;
 use LedgerSMB::CancelFurtherProcessing;
@@ -882,6 +883,7 @@
     }
     $self->{dbh}->{pg_server_prepare} = 0;
     $self->{dbh}->{pg_enable_utf8} = 1;
+    $LedgerSMB::App_State::DBH = $self->{dbh};
 
     # This is the general version check
     my $sth = $self->{dbh}->prepare("

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