[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4960] branches/1.3
- Subject: SF.net SVN: ledger-smb:[4960] branches/1.3
- From: ..hidden..
- Date: Tue, 10 Jul 2012 08:41:19 +0000
Revision: 4960
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4960&view=rev
Author: einhverfr
Date: 2012-07-10 08:41:17 +0000 (Tue, 10 Jul 2012)
Log Message:
-----------
Backporting App_State from trunk to make other backports more feasible
Modified Paths:
--------------
branches/1.3/Changelog
branches/1.3/LedgerSMB/Form.pm
branches/1.3/LedgerSMB.pm
branches/1.3/lsmb-request.pl
branches/1.3/old-handler.pl
Added Paths:
-----------
branches/1.3/LedgerSMB/App_State.pm
Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog 2012-07-05 01:57:32 UTC (rev 4959)
+++ branches/1.3/Changelog 2012-07-10 08:41:17 UTC (rev 4960)
@@ -12,11 +12,14 @@
* Added access to parts.image for ar invoice, order, quote templates (Chris T)
* Fixed error on redirect from attaching file to part (Chris T h/t Brian W)
* Fixed inability to look up vendor by ECA with discounts (Erik H h/t Matt B)
+* Removed broken cash-basis reports (Chris T, h/t Jigme D
+* Backporting LedgerSMB::App_State to make other backports easier (Chris T)
Andres B is Andres Basile
Brian W is Brian Wolf
Chris T is Chris Travers
Erik H is Erik Huelsmann
+Jigme D is JigmeDatse
Matt B is Matthew Bourque
Changelog for 1.3.19
Added: branches/1.3/LedgerSMB/App_State.pm
===================================================================
--- branches/1.3/LedgerSMB/App_State.pm (rev 0)
+++ branches/1.3/LedgerSMB/App_State.pm 2012-07-10 08:41:17 UTC (rev 4960)
@@ -0,0 +1,208 @@
+=head1 NAME
+
+LedgerSMB::App_State
+
+=cut
+package LedgerSMB::App_State;
+use strict;
+use warnings;
+use LedgerSMB::Sysconfig;
+use LedgerSMB::User;
+use LedgerSMB::Locale;
+
+=head1 SYNPOSIS
+
+This is a generic container class for non-web-application related state
+information. It provides a central place to track such things as localization,
+user, and other application state objects.
+
+=head1 OBJECTS FOR STORAGE
+
+The following are objects that are expected to be stored in this namespace:
+
+=over
+
+=cut
+
+our $Locale;
+
+=item Locale
+
+Stores a LedgerSMB::Locale object for the specific user.
+
+=cut
+
+our $User;
+
+=item User
+
+Stores a LedgerSMB::User object for the currently logged in user.
+
+=cut
+
+our $Company_Settings;
+
+=item Company_Settings
+
+Hashref for storing connection-specific settings for the application.
+
+=item DBH
+
+Database handle for current connection
+
+=cut
+
+our $DBH;
+
+
+=item Roles
+
+This is a list (array) of role names for the current user.
+
+=cut
+
+our @Roles;
+
+=item Role_Prefix
+
+String of the beginning of the role.
+
+=cut
+
+our $Role_Prefix;
+
+=item DBName
+
+name of the database connecting to
+
+=cut
+
+our $DBName;
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item zero()
+
+zeroes out all majro parts.
+
+=cut
+
+sub zero() {
+ $User = undef;
+ $Locale = undef;
+ $DBH = undef;
+ @Roles = ();
+ $DBName = undef;
+ $Role_Prefix = undef;
+}
+
+=item cleanup
+
+Deletes all objects attached here.
+
+=cut
+
+sub cleanup {
+
+ if ($DBH){
+ $DBH->commit;
+ $DBH->disconnect;
+ }
+ $Locale = LedgerSMB::Locale->get_handle(
+ $LedgerSMB::Sysconfig::language
+ );
+ $User = {};
+ $Company_Settings = {};
+ $DBH = undef;
+ $DBName = undef;
+ @Roles = ();
+ $Role_Prefix = undef;
+}
+
+1;
+
+=item get_url
+
+Returns URL of get request or undef
+
+=cut
+
+sub get_url {
+ if ($ENV{REQUEST_METHOD} ne 'GET') {
+ return undef;
+ }
+ return "$ENV{SCRIPT_NAME}?$ENV{QUERY_STRING}";
+}
+
+=item all_months(is_short $bool)
+
+Returns hashref of localized date data with following members:
+
+If $is_short is set and true, returns short names (Jan, Feb, etc) instead of
+long names (January, February, etc).
+
+=over
+
+=item dropdown
+
+Month information in drop down format.
+
+=item hashref
+
+Month info in hashref format in 01 => January format
+
+=back
+
+=cut
+
+sub all_months {
+ my ($self, $is_short) = @_;
+ my $i18n = $Locale;
+ my $months = {
+ '01' => {long => $i18n->text('January'), short => $i18n->text('Jan'), },
+ '02' => {long => $i18n->text('February'), short => $i18n->text('Feb'), },
+ '03' => {long => $i18n->text('March'), short => $i18n->text('Mar'), },
+ '04' => {long => $i18n->text('April'), short => $i18n->text('Apr'), },
+ # XXX That's asking for trouble below. Need to update .po files
+ # before changing however. --CT
+ '05' => {long => $i18n->text('May'), short => $i18n->text('May'), },
+ '06' => {long => $i18n->text('June'), short => $i18n->text('Jun'), },
+ '07' => {long => $i18n->text('July'), short => $i18n->text('Jul'), },
+ '08' => {long => $i18n->text('August'), short => $i18n->text('Aug'), },
+ '09' => {long => $i18n->text('September'), short => $i18n->text('Sep'), },
+ '10' => {long => $i18n->text('October'), short => $i18n->text('Oct'), },
+ '11' => {long => $i18n->text('November'), short => $i18n->text('Nov'), },
+ '12' => {long => $i18n->text('December'), short => $i18n->text('Dec'), },
+ };
+
+ my $for_dropdown = [];
+ my $as_hashref = {};
+ for my $key (sort {$a cmp $b} keys %$months){
+ my $mname;
+ if ($is_short){
+ $mname = $months->{$key}->{short};
+ } else {
+ $mname = $months->{$key}->{long};
+ }
+ $as_hashref->{$key} = $mname;
+ push @$for_dropdown, {text => $mname, value => $key};
+ }
+ return { as_hashref => $as_hashref, dropdown=> $for_dropdown };
+}
+
+=back
+
+
+=head1 COPYRIGHT
+
+Copyright (C) 2009 LedgerSMB Core Team. This file is licensed under the GNU
+General Public License version 2, or at your option any later version. Please
+see the included License.txt for details.
+
+=cut
+
+1;
Modified: branches/1.3/LedgerSMB/Form.pm
===================================================================
--- branches/1.3/LedgerSMB/Form.pm 2012-07-05 01:57:32 UTC (rev 4959)
+++ branches/1.3/LedgerSMB/Form.pm 2012-07-10 08:41:17 UTC (rev 4960)
@@ -66,6 +66,7 @@
use Cwd;
use File::Copy;
use LedgerSMB::Company_Config;
+use LedgerSMB::App_State;
use charnames qw(:full);
use open ':utf8';
@@ -1396,6 +1397,9 @@
while (my @roles = $sth->fetchrow_array){
push @{$self->{_roles}}, $roles[0];
}
+ $LedgerSMB::App_State::Roles = @{$self->{_roles}};
+ $LedgerSMB::App_State::Role_Prefix = $self->{_role_prefix};
+ $LedgerSMB::App_State::DBName = $dbname;
$sth = $dbh->prepare('SELECT check_expiration()');
$sth->execute;
@@ -1405,6 +1409,7 @@
$sth->execute;
($self->{pw_expires}) = $sth->fetchrow_array;
}
+ $LedgerSMB::App_State::DBH = $self->{dbh};
LedgerSMB::Company_Config::initialize($self);
$sth->finish();
$logger->trace("end");
Modified: branches/1.3/LedgerSMB.pm
===================================================================
--- branches/1.3/LedgerSMB.pm 2012-07-05 01:57:32 UTC (rev 4959)
+++ branches/1.3/LedgerSMB.pm 2012-07-10 08:41:17 UTC (rev 4960)
@@ -213,6 +213,7 @@
use LedgerSMB::Locale;
use LedgerSMB::User;
use LedgerSMB::Setting;
+use LedgerSMB::App_State;
use LedgerSMB::Log;
use LedgerSMB::Company_Config;
use strict;
@@ -781,6 +782,7 @@
my $procname = $args{procname};
my $schema = $args{schema};
my @call_args;
+ my $dbh = $LedgerSMB::App_State::DBH;
@call_args = @{ $args{args} } if defined $args{args};
my $order_by = $args{order_by};
my $query_rc;
@@ -790,13 +792,13 @@
if (!defined $procname){
$self->error('Undefined function in call_procedure.');
}
- $procname = $self->{dbh}->quote_identifier($procname);
+ $procname = $dbh->quote_identifier($procname);
# Add the test for whether the schema is something useful.
$logger->trace("\$procname=$procname");
$schema = $schema || $LedgerSMB::Sysconfig::db_namespace;
- $schema = $self->{dbh}->quote_identifier($schema);
+ $schema = $dbh->quote_identifier($schema);
for ( 1 .. scalar @call_args ) {
$argstr .= "?, ";
@@ -807,7 +809,7 @@
$query .= " ORDER BY $order_by";
}
$query =~ s/\(\)/($argstr)/;
- my $sth = $self->{dbh}->prepare($query);
+ my $sth = $dbh->prepare($query);
my $place = 1;
# API Change here to support byteas:
# If the argument is a hashref, allow it to define it's SQL type
@@ -828,10 +830,10 @@
$query_rc = $sth->execute();
if (!$query_rc){
if ($args{continue_on_error} and # only for plpgsql exceptions
- ($self->{dbh}->state =~ /^P/)){
- $@ = $self->{dbh}->errstr;
+ ($dbh->state =~ /^P/)){
+ $@ = $dbh->errstr;
} else {
- $self->dberror($self->{dbh}->errstr . ": " . $query);
+ $self->dberror($dbh->errstr . ": " . $query);
}
}
@@ -1002,6 +1004,8 @@
}
$self->{dbh}->{pg_server_prepare} = 0;
$self->{dbh}->{pg_enable_utf8} = 1;
+ $LedgerSMB::App_State::DBH = $self->{dbh};
+ $LedgerSMB::App_State::DBName = $dbname;
# This is the general version check
my $sth = $self->{dbh}->prepare("
@@ -1054,6 +1058,10 @@
while (my @roles = $sth->fetchrow_array){
push @{$self->{_roles}}, $roles[0];
}
+ $LedgerSMB::App_State::Roles = @{$self->{_roles}};
+ $LedgerSMB::App_State::Role_Prefix = $self->{_role_prefix};
+ # @{$self->{_roles}} will eventually go away. --CT
+
$sth->finish();
$logger->debug("end");
}
@@ -1068,30 +1076,32 @@
sub dberror{
my $self = shift @_;
my $state_error = {};
- if ($self->{_locale}){
+ my $locale = $LedgerSMB::App_State::Locale;
+ my $dbh = $LedgerSMB::App_State::DBH;
+ if ($locale){
$state_error = {
- '42883' => $self->{_locale}->text('Internal Database Error'),
- '42501' => $self->{_locale}->text('Access Denied'),
- '42401' => $self->{_locale}->text('Access Denied'),
- '22008' => $self->{_locale}->text('Invalid date/time entered'),
- '22012' => $self->{_locale}->text('Division by 0 error'),
- '22004' => $self->{_locale}->text('Required input not provided'),
- '23502' => $self->{_locale}->text('Required input not provided'),
- '23505' => $self->{_locale}->text('Conflict with Existing Data. Perhaps you already entered this?'),
- 'P0001' => $self->{_locale}->text('Error from Function:') . "\n" .
- $self->{dbh}->errstr,
+ '42883' => $locale->text('Internal Database Error'),
+ '42501' => $locale->text('Access Denied'),
+ '42401' => $locale->text('Access Denied'),
+ '22008' => $locale->text('Invalid date/time entered'),
+ '22012' => $locale->text('Division by 0 error'),
+ '22004' => $locale->text('Required input not provided'),
+ '23502' => $locale->text('Required input not provided'),
+ '23505' => $locale->text('Conflict with Existing Data. Perhaps you already entered this?'),
+ 'P0001' => $locale->text('Error from Function:') . "\n" .
+ $dbh->errstr,
};
}
- $logger->error("Logging SQL State ".$self->{dbh}->state.", error ".
- $self->{dbh}->err . ", string " .$self->{dbh}->errstr);
- if (defined $state_error->{$self->{dbh}->state}){
- $self->error($state_error->{$self->{dbh}->state}
+ $logger->error("Logging SQL State ".$dbh->state.", error ".
+ $dbh->err . ", string " .$dbh->errstr);
+ if (defined $state_error->{$dbh->state}){
+ $self->error($state_error->{$dbh->state}
. "\n" .
- $self->{_locale}->text('More information has been reported in the error logs'));
- $self->{dbh}->rollback;
+ $locale->text('More information has been reported in the error logs'));
+ $dbh->rollback;
exit;
}
- $self->error($self->{dbh}->state . ":" . $self->{dbh}->errstr);
+ $self->error($dbh->state . ":" . $dbh->errstr);
}
sub redo_rows {
Modified: branches/1.3/lsmb-request.pl
===================================================================
--- branches/1.3/lsmb-request.pl 2012-07-05 01:57:32 UTC (rev 4959)
+++ branches/1.3/lsmb-request.pl 2012-07-10 08:41:17 UTC (rev 4960)
@@ -34,8 +34,10 @@
use Data::Dumper;
use LedgerSMB::Log;
use LedgerSMB::CancelFurtherProcessing;
+use LedgerSMB::App_State;
use strict;
+LedgerSMB::App_State->zero();
my $logger = Log::Log4perl->get_logger('LedgerSMB::Handler');
Log::Log4perl::init(\$LedgerSMB::Sysconfig::log4perl_config);
$logger->debug("Begin");
@@ -59,10 +61,13 @@
my $locale;
if ($request->{_user}){
+ $LedgerSMB::App_State::User = $request->{_user};
$locale = LedgerSMB::Locale->get_handle($request->{_user}->{language});
+ $LedgerSMB::App_State::Locale = $locale;
} else {
$locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
or $request->error( __FILE__ . ':' . __LINE__ . ": Locale not loaded: $!\n" );
+ $LedgerSMB::App_State::Locale = $locale;
}
if (!$script){
@@ -96,10 +101,12 @@
$script->can($request->{action})
|| $request->error($locale->text("Action Not Defined: ") . $request->{action});
$script->can( $request->{action} )->($request);
+ LedgerSMB::App_State->cleanup();
}
catch CancelFurtherProcessing with {
my $ex = shift;
$logger->debug("CancelFurtherProcessing \$ex=$ex");
+ LedgerSMB::App_State->cleanup();
};
}
1;
Modified: branches/1.3/old-handler.pl
===================================================================
--- branches/1.3/old-handler.pl 2012-07-05 01:57:32 UTC (rev 4959)
+++ branches/1.3/old-handler.pl 2012-07-10 08:41:17 UTC (rev 4960)
@@ -49,6 +49,7 @@
use LedgerSMB::Sysconfig;
use Digest::MD5;
use Error qw(:try);
+use LedgerSMB::App_State;
$| = 1;
@@ -159,7 +160,7 @@
. " $form->{version} - $myconfig{name} - $myconfig{dbname}";
&{ $form->{action} };
-
+ LedgerSMB::App_State::cleanup();
}
else {
$form->error( __FILE__ . ':' . __LINE__ . ': '
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.