From 676518fe846390fbb3b20016298eabb024dcb24f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 5 May 2025 18:37:33 +0000 Subject: [PATCH] Bug 39180: Catch exception when updating patron lastseen date This patch adds a catch during checkin and passes a message back to the caller For checkouts and renewals we don't have a method for passing messages so we simply catch the exception and warn - this seems reasonable, I think we should add a warning on the patron display that a required guarantor is missing, but not break circulation. We will need to add unit tests --- C4/Circulation.pm | 27 ++++++++++++++++--- circ/returns.pl | 2 ++ .../prog/en/modules/circ/returns.tt | 7 +++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index abea785d9a9..6910eca8834 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -22,6 +22,7 @@ use Modern::Perl; use DateTime; use POSIX qw( floor ); use Encode; +use Try::Tiny; use C4::Context; use C4::Stats qw( UpdateStats ); @@ -1778,7 +1779,14 @@ sub AddIssue { ); } $issue->discard_changes; - $patron->update_lastseen('check_out'); + #Update borrowers.lastseen + try{ + $patron->update_lastseen('check_out'); + } + catch { + my $exception = $_; + warn "Problem updating lastseen date for borrowernumber " . $patron->borrowernumber . ": $exception"; + }; if ( $item_object->location && $item_object->location eq 'CART' && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) @@ -2571,7 +2579,14 @@ sub AddReturn { if C4::Context->preference("ReturnLog"); #Update borrowers.lastseen - $patron->update_lastseen('check_in'); + try{ + $patron->update_lastseen('check_in'); + } + catch { + my $exception = $_; + warn "Problem updating lastseen date for borrowernumber " . $patron->borrowernumber . ": $exception"; + $messages->{UpdateLastSeenError} = "$exception"; + }; } # Check if this item belongs to a biblio record that is attached to an @@ -3519,7 +3534,13 @@ sub AddRenewal { ); #Update borrowers.lastseen - $patron->update_lastseen('renewal'); + try{ + $patron->update_lastseen('renewal'); + } + catch { + my $exception = $_; + warn "Problem updating lastseen date for borrowernumber " . $patron->borrowernumber . ": $exception"; + }; #Log the renewal logaction( "CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber ) diff --git a/circ/returns.pl b/circ/returns.pl index 9a55093893f..70c5b02e0f9 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -743,6 +743,8 @@ foreach my $code ( keys %$messages ) { ; } elsif ( $code eq 'InBundle' ) { $template->param( InBundle => $messages->{InBundle} ); + } elsif ( $code eq 'UpdateLastSeenError' ) { + $err{UpdateLastSeenError} = $messages->{UpdateLastSeenError}; } else { die "Unknown error code $code"; # note we need all the (empty) elsif's above, or we die. # This forces the issue of staying in sync w/ Circulation.pm diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 0309793b6fe..7a191c20161 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -294,6 +294,13 @@ [% END %]

[% END %] + [% IF ( errmsgloo.UpdateLastSeenError ) %] +
+

Error updating patron's last seen date

+

The system encountered an error when updating the patron's last seen date:

+

[% errmsgloo.UpdateLastSeenError | html %]

+
+ [% END %] [% IF ( errmsgloo.ItemLocationUpdated ) %]

Item shelving location updated. -- 2.39.5