From ea74c996834fd5124fe73c893785950b28d932d1 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 13 Nov 2020 08:24:43 -0500 Subject: [PATCH] Bug 27014: Enable C4::SIP::ILS::Patron::new to accept a hash Caused by bug 23403 - when performing a checkin we lookup the SIP patron using the borrowernumber, however, SIP only knows how to find a patron via cardnumber or userid The change on 23403 was to avoid using an 'id' that didn't always exist (as some users don't have a userid or cardnumber When checking in, however, we are not passed a user cardnumber or borrowernumber, so we don't have those on hand to get the patron. Test Plan: 1) Check in an item via SIP, note patron is not found 2) Apply this patch 3) Restart all the things! 4) Check in an item via SIP, patron should be found! Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 05e16389efa6e66476484ee12c3a5c5fdd48757b) Signed-off-by: Fridolin Somers --- C4/SIP/ILS.pm | 2 +- C4/SIP/ILS/Patron.pm | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index f74045319c..2b71bcd176 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -243,7 +243,7 @@ sub checkin { siplog("LOG_DEBUG", "C4::SIP::ILS::Checkin - item not checked out"); } } elsif ( $circ->ok ) { - $circ->patron( $patron = C4::SIP::ILS::Patron->new( $item->{borrowernumber} ) ); + $circ->patron( $patron = C4::SIP::ILS::Patron->new( { borrowernumber => $item->{borrowernumber} } ) ); delete $item->{borrowernumber}; delete $item->{due_date}; $patron->{items} = [ grep { $_ ne $item_id } @{ $patron->{items} } ]; diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index b6a75ad77f..d5ac629023 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -38,8 +38,21 @@ sub new { my ($class, $patron_id) = @_; my $type = ref($class) || $class; my $self; - my $patron = Koha::Patrons->find( { cardnumber => $patron_id } ) - || Koha::Patrons->find( { userid => $patron_id } ); + + my $patron; + if ( ref $patron_id eq "HASH" ) { + if ( $patron_id->{borrowernumber} ) { + $patron = Koha::Patrons->find( $patron_id->{borrowernumber} ); + } elsif ( $patron_id->{cardnumber} ) { + $patron = Koha::Patrons->find( { cardnumber => $patron_id->{cardnumber} } ); + } elsif ( $patron_id->{userid} ) { + $patron = Koha::Patrons->find( { userid => $patron_id->{userid} } ); + } + } else { + $patron = Koha::Patrons->find( { cardnumber => $patron_id } ) + || Koha::Patrons->find( { userid => $patron_id } ); + } + $debug and warn "new Patron: " . Dumper($patron->unblessed) if $patron; unless ($patron) { siplog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id); -- 2.39.5