From: Bill Erickson <berick@esilibrary.com>
Date: Fri, 17 Aug 2012 14:08:16 +0000 (-0400)
Subject: CStoreEditor default session locale
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7ddaf5917669985f80f5d737c75d24d3cdfd616e;p=evergreen%2Fmasslnc.git

CStoreEditor default session locale

Adds a new package-level variable:

$OpenILS::Utils::CStoreEditor::default_locale

If set, this value is used as the session_locale for new opensrf client
sessions.  If unset, the session_locale remains untouched by
CStoreEditor.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
---

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
index d41e435e26..51854e3a77 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
@@ -13,6 +13,10 @@ my %PERMS;
 my $cache;
 my %xact_ed_cache;
 
+# if set, we will use this locale for all new sessions
+# if unset, we rely on the existing opensrf locale propagation
+our $default_locale;
+
 our $always_xact = 0;
 our $_loaded = 1;
 
@@ -207,8 +211,17 @@ sub session {
 	my( $self, $session ) = @_;
 	$self->{session} = $session if $session;
 
+	# sessions can stick around longer than a single request/transaction.
+	# kill it if our default locale was altered since the last request
+	# and it does not match the locale of the existing session.
+	delete $self->{session} if
+		$default_locale and
+		$self->{session} and
+		$self->{session}->session_locale ne $default_locale;
+
 	if(!$self->{session}) {
 		$self->{session} = OpenSRF::AppSession->create($self->app);
+		$self->{session}->session_locale($default_locale) if $default_locale;
 
 		if( ! $self->{session} ) {
 			my $str = "Error creating cstore session with OpenSRF::AppSession->create()!";