From 4e2facd41967019fa2b9b0e8e10c07f7a6ed1936 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 --- 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 d2a253873b..ddf4fed4db 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 9820013ee7..237f854487 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.20.1