Bug 11182: (follow-up) fix regression where session branch wasn't initialized
authorGalen Charlton <gmc@esilibrary.com>
Fri, 2 May 2014 20:25:22 +0000 (20:25 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 2 May 2014 20:25:22 +0000 (20:25 +0000)
C4::Context->userenv() won't return a valid value until the
user session set up, e.g., via get_template_and_user().  Consequently,
the change introduced by a previous commit for bug 11182 ended
up making it appear that when checking an item that fills a hold
that it always needs to be transferred.

This patch fixes the regression and moves the "no-branch-set" check
to where it belongs.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
circ/returns.pl

index cb5ccf1..55888a6 100755 (executable)
@@ -49,17 +49,6 @@ use Koha::Calendar;
 
 my $query = new CGI;
 
-my $userenv = C4::Context->userenv;
-if (!$userenv){
-    my $sessionID = $query->cookie("CGISESSID");
-    my $session = get_session($sessionID);
-    if ($session->param('branch') eq 'NO_LIBRARY_SET'){
-        # no branch set we can't return
-        print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
-        exit;
-    }
-} 
-
 #getting the template
 my ( $template, $librarian, $cookie ) = get_template_and_user(
     {
@@ -71,10 +60,19 @@ my ( $template, $librarian, $cookie ) = get_template_and_user(
     }
 );
 
+my $sessionID = $query->cookie("CGISESSID");
+my $session = get_session($sessionID);
+if ($session->param('branch') eq 'NO_LIBRARY_SET'){
+    # no branch set we can't return
+    print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
+    exit;
+}
+
 #####################
 #Global vars
 my $branches = GetBranches();
 my $printers = GetPrinters();
+my $userenv = C4::Context->userenv;
 my $userenv_branch = $userenv->{'branch'} // '';
 my $printer = $userenv->{'branchprinter'} // '';