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 <david@davidnind.com>
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2025-05-05 18:37:33 +00:00 committed by Lucas Gass
parent 4b300b1c1d
commit bd32425271
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
3 changed files with 34 additions and 3 deletions

View File

@ -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 )

View File

@ -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

View File

@ -294,6 +294,14 @@
[% END %]
</p>
[% END %]
[% IF ( errmsgloo.UpdateLastSeenError ) %]
<div id="update_last_seen_error" class="alert alert-warning audio-alert-warning">
<h3>Error updating patron's last seen date</h3>
<p>The item has been checked in, but the issue below must be corrected:</p>
<p>The system encountered an error when updating the patron's last seen date:</p>
<p>[% errmsgloo.UpdateLastSeenError | html %]</p>
</div>
[% END %]
[% IF ( errmsgloo.ItemLocationUpdated ) %]
<p class="problem ret_location_update">
Item shelving location updated.