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 <martin.renvoize@openfifth.co.uk> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
c074c66d51
commit
599286cf40
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue