From 30a4bf57197d751ba2cafac3d21dfb69aa67fb24 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 11 Oct 2024 12:28:48 +0000 Subject: [PATCH] Bug 30648: Record deleted_biblionumber in holds This patch ensures the deleted biblionumber is recorded in current and previous holds before the record is deleted To test: 1 - Place and fill a few holds on a biblio, completing checkout to patron 2 - Place a few holds on the biblio and do not fulfill them 3 - Delete the items from the biblio via the DB (otherwise you cannot delete last item when there are holds) DELETE FROM items WHERE biblionumber={biblionumber} 4 - Delete the biblio 5 - Check the DB and confirm the deleted_biblionumber column has been filled SELECT reserve_id,deleted_biblionumber,biblionumber FROM old_reserves WHERE deleted_biblionumber = {biblionumber}; 6 - Sign off! --- C4/Biblio.pm | 3 +++ Koha/Biblio.pm | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 54055aec2a4..1a88d52bdb9 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -554,6 +554,9 @@ sub DelBiblio { # We delete any existing holds my $holds = $biblio->holds; + $holds->update({ deleted_biblionumber => $biblionumber }, { no_triggers => 1 }); + my $old_holds = $biblio->old_holds; + $old_holds->update({ deleted_biblionumber => $biblionumber }, { no_triggers => 1 }); while ( my $hold = $holds->next ) { # no need to update the holds queue on each step, we'll do it at the end $hold->cancel({ skip_holds_queue => 1 }); diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 8829a3e63c5..e2c047d0c81 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -52,6 +52,7 @@ use Koha::Item::Transfer::Limits; use Koha::Items; use Koha::Libraries; use Koha::Old::Checkouts; +use Koha::Old::Holds; use Koha::Ratings; use Koha::Recalls; use Koha::RecordProcessor; @@ -708,6 +709,21 @@ sub holds { return Koha::Holds->_new_from_dbic($hold_rs); } +=head3 old_holds + +my $old_holds = $biblio->old_holds(); + +return the historic holds placed on this record + +=cut + +sub old_holds { + my ( $self, $params, $attributes ) = @_; + $attributes->{order_by} = 'priority' unless exists $attributes->{order_by}; + my $old_hold_rs = $self->_result->old_reserves->search( $params, $attributes ); + return Koha::Old::Holds->_new_from_dbic($old_hold_rs); +} + =head3 current_holds my $holds = $biblio->current_holds -- 2.39.5