From 21fab508bd14b98343c076c3f2f807aff2644fa0 Mon Sep 17 00:00:00 2001
From: David Cook <dcook@prosentient.com.au>
Date: Fri, 13 Jul 2012 11:50:04 +1000
Subject: [PATCH] Bug 8434 - Notice generation fails for Advanced Notices,
 Item Due, and Overdues when run in shell (due to error in
 Letters.pm)
Content-Type: text/plain; charset="utf-8"

Patch introduces a check for C4::Context->userenv in Letters.pm, so that script doesn't fail when it calls to C4::Context->userenv->{branch}, when run from shell.

Without the check, Advanced Notices, Item Due, and Overdues fail to generate.
---
 C4/Letters.pm |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/C4/Letters.pm b/C4/Letters.pm
index 893419c..d13ce13 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -121,7 +121,9 @@ sub getletter ($$$) {
     my ( $module, $code, $branchcode ) = @_;
 
     if (C4::Context->preference('IndependantBranches') && $branchcode){
+        if (C4::Context->userenv) {
         $branchcode = C4::Context->userenv->{'branch'};
+        }
     }
 
     if ( my $l = $letter{$module}{$code}{$branchcode} ) {
-- 
1.7.7.4