From 0ae7f364ffcb85452005e76e6cccd58d97a53993 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 21 Nov 2025 08:25:48 +0100 Subject: [PATCH] Bug 30255: Improve handling of non-existant record ids in modification/deletion background jobs --- Koha/BackgroundJob/BatchDeleteBiblio.pm | 2 ++ Koha/BackgroundJob/BatchUpdateAuthority.pm | 4 +++- Koha/BackgroundJob/BatchUpdateBiblio.pm | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm index 3bc7f7336ee..1ce75f4c437 100644 --- a/Koha/BackgroundJob/BatchDeleteBiblio.pm +++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm @@ -72,6 +72,8 @@ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { # If yes, nothing to do my $biblio = Koha::Biblios->find($biblionumber); + next unless $biblio; + # TODO Replace with $biblio->get_issues->count if ( C4::Biblio::CountItemsIssued($biblionumber) ) { push @messages, { diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm index f19dddca600..ec7128f02c0 100644 --- a/Koha/BackgroundJob/BatchUpdateAuthority.pm +++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm @@ -76,7 +76,9 @@ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { my $authid = $record_id; my $error = eval { my $authority = Koha::MetadataRecord::Authority->get_from_authid($authid); - my $record = $authority->record; + die("Invalid authid: $authid") unless $authority; + + my $record = $authority->record; ModifyRecordWithTemplate( $mmtid, $record ); ModAuthority( $authid, $record, $authority->authtypecode, { skip_record_index => 1 } ); }; diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm index bbd4a7a5453..3ae601306c4 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -85,6 +85,8 @@ RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { my $error = eval { my $biblio = Koha::Biblios->find($biblionumber); my $record = $biblio->metadata->record; + die("Invalid biblionumber: $biblionumber") unless $record; + C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); -- 2.51.2