Bug 19074: Do not crash if cardnumber does not exist
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 10 Aug 2017 18:20:43 +0000 (15:20 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 10 Aug 2017 19:25:33 +0000 (16:25 -0300)
If a cardnumber does not exist, $borrower will be undef and the ->category call will explode
Can't call method "category" on an undefined value at
/home/vagrant/kohaclone/tools/modborrowers.pl line 370.

This patch makes sure the patron exists before calling any methods.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

tools/modborrowers.pl

index 7acc9a8..3b83f2b 100755 (executable)
@@ -366,10 +366,10 @@ exit;
 
 sub GetBorrowerInfos {
     my ( %info ) = @_;
-    my $borrower = Koha::Patrons->find( \%info );
-    my $catdesc = $borrower->category->description;
-    if ( $borrower ) {
-        $borrower = $borrower->unblessed;
+    my $patron = Koha::Patrons->find( \%info );
+    my $borrower;
+    if ( $patron ) {
+        $borrower = $patron->unblessed;
         for ( qw(dateenrolled dateexpiry) ) {
             my $userdate = $borrower->{$_};
             unless ($userdate && $userdate ne "0000-00-00" and $userdate ne "9999-12-31") {
@@ -378,7 +378,7 @@ sub GetBorrowerInfos {
             }
             $borrower->{$_} = $userdate || '';
         }
-        $borrower->{category_description} = $catdesc;
+        $borrower->{category_description} = $patron->category->description;
         my $attr_loop = C4::Members::Attributes::GetBorrowerAttributes( $borrower->{borrowernumber} );
         $borrower->{patron_attributes} = $attr_loop;
     }