CStoreEditor default session locale
authorBill Erickson <berick@esilibrary.com>
Fri, 17 Aug 2012 14:08:16 +0000 (10:08 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 20 Aug 2012 20:16:50 +0000 (16:16 -0400)
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>

Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm

index d41e435..51854e3 100644 (file)
@@ -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()!";