From af5ee4b4b8f5cfd194ec2dbe3f31fb73578dc6ea Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 30 Jan 2026 11:01:37 +0000 Subject: [PATCH] Bug 23260: (QA follow-up) Validate AnonymousPatron preference value Add validation to ensure AnonymousPatron preference contains a valid borrowernumber before attempting to use it in the anonymization process. This prevents foreign key constraint errors and orphaned records if the preference contains an invalid value (non-existent borrowernumber, string instead of number, etc.). Signed-off-by: Martin Renvoize --- Koha/Patrons.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 65131c0463d..8b802bdb53a 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -204,14 +204,17 @@ sub anonymize_last_borrowers { my ( $self, $params ) = @_; return unless C4::Context->preference("AnonymizeLastBorrower"); - return unless C4::Context->preference("AnonymousPatron"); + + my $anonymous_patron = C4::Context->preference('AnonymousPatron'); + return unless $anonymous_patron; + my $anon_patron_obj = Koha::Patrons->find($anonymous_patron); + return unless $anon_patron_obj; # Invalid AnonymousPatron value + my $days = C4::Context->preference("AnonymizeLastBorrowerDays") || 0; my ( $year, $month, $day ) = Today(); my ( $newyear, $newmonth, $newday ) = Add_Delta_Days( $year, $month, $day, (-1) * $days ); my $older_than_date = dt_from_string( sprintf "%4d-%02d-%02d", $newyear, $newmonth, $newday ); - my $anonymous_patron = C4::Context->preference('AnonymousPatron'); - my $dtf = Koha::Database->new->schema->storage->datetime_parser; # Perform bulk update directly on items_last_borrower table to avoid N+1 queries -- 2.52.0