From 80eb3ff7e8bd84a58bfa76e58dafe4c5e8f243b7 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 circulatoin actions 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, as we have now added a warning on the patron display that they are missing
a guarantor
To test:
1 - Create a Child type patron with no guarantor
2 - Create a patron in a non-child category that can_be_guarantee with no guarantor
3 - Check out an item to each patron above
4 - Enable system preference 'ChildNeedsGuarantor' and TrackLastPatronActivityTriggers - select all
5 - In mysql
UPDATE borrowers SET datelastseen = '2025-01-01';
6 - Restart all to clear cache (so update last seen will update)
7 - Attempt to checkout a book to either patron - 500 error
8 - Attempt to returnt he books the patrons have checked out - 500 error
9 - Attempt to renew their items - 500 error
10 - Apply patches, restart all
11 - Repeat checkout, renewal, checkin
12 - On checkout and renewal there should be a warning on the patron page, but actions succeed with no additional problems
13 - On return you get a warning letting you know the action succeeded but there is still a problem to resolve
Signed-off-by: David Nind
---
C4/Circulation.pm | 27 ++++++++++++++++---
circ/returns.pl | 2 ++
.../prog/en/modules/circ/returns.tt | 8 ++++++
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 733177a552..165ada2ef7 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 );
@@ -1783,7 +1784,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' ) )
@@ -2581,7 +2589,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
@@ -3529,7 +3544,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 9a55093893..70c5b02e0f 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 0309793b6f..1634b826d6 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,14 @@
[% END %]
[% END %]
+ [% IF ( errmsgloo.UpdateLastSeenError ) %]
+
+
Error updating patron's last seen date
+
The item has been checked in, but the issue below must be corrected:
+
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