From 6d6fab4144a093d470d6d23f7cab82a4e5fe8111 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 | 1 + Koha/BackgroundJob/BatchUpdateAuthority.pm | 6 ++++-- Koha/BackgroundJob/BatchUpdateBiblio.pm | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm index 3bc7f7336ee..4385025972b 100644 --- a/Koha/BackgroundJob/BatchDeleteBiblio.pm +++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm @@ -71,6 +71,7 @@ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { # First, checking if issues exist. # 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) ) { diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm index f19dddca600..b695aec5166 100644 --- a/Koha/BackgroundJob/BatchUpdateAuthority.pm +++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm @@ -76,11 +76,13 @@ 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 } ); }; - if ( $error and $error != $authid or $@ ) { + if ( $error && $error != $authid || $@ ) { push @messages, { type => 'error', code => 'authority_not_modified', diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm index bbd4a7a5453..fbe55619d56 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -84,6 +84,8 @@ RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { # Modify the biblio my $error = eval { my $biblio = Koha::Biblios->find($biblionumber); + die("Invalid biblionumber: $biblionumber") unless $biblio; + my $record = $biblio->metadata->record; C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); @@ -106,7 +108,7 @@ RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { } ); }; - if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well + if ( $error && $error != 1 || $@ ) { # ModBiblio returns 1 if everything as gone well push @messages, { type => 'error', code => 'biblio_not_modified', -- 2.51.2