From aca6cae69f77a7eae494bbf1f34ac6ce5eef2fbd Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Wed, 11 Mar 2020 19:33:15 -0400 Subject: [PATCH] LP#1398107: Alert when autodeleting a title with holds on it. Add a new "TITLE_HAS_HOLDS" event that we pass up to the user if any non-canceled, unfulfilled title hold targets a bib that would otherwise be silently deleted with holds canceled. Also, retarget any holds pointing to a bib that is automatically deleted after removing its volumes/copies to the destination bib if this is the last copy. Signed-off-by: Chris Sharp Signed-off-by: Rogan Hamby Signed-off-by: Jason Stephenson --- Open-ILS/src/extras/ils_events.xml | 6 ++++++ .../src/perlmods/lib/OpenILS/Application/Cat.pm | 12 ++++++++--- .../lib/OpenILS/Application/Cat/AssetCommon.pm | 6 ++++++ .../lib/OpenILS/Application/Cat/BibCommon.pm | 23 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index ce36cc6d81..527c61215a 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -1086,6 +1086,12 @@ The item to be marked is the last possible target for a hold. + + + + + This title has hold requests on it that will be canceled if they are not transferred. + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 36376a0948..d072dd167d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -1532,11 +1532,17 @@ sub batch_volume_transfer { # Now see if any empty records need to be deleted after all of this my $keep_on_empty = $U->ou_ancestor_setting_value($e->requestor->ws_ou, 'cat.bib.keep_on_empty', $e); unless ($U->is_true($keep_on_empty)) { + for (@rec_ids) { $logger->debug("merge: seeing if we should delete record $_..."); - $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $_) - if OpenILS::Application::Cat::BibCommon->title_is_empty($e, $_); - return $evt if $evt; + if (OpenILS::Application::Cat::BibCommon->title_is_empty($e, $_)) { + # check for any title holds on the bib, bail if so + my $has_holds = OpenILS::Application::Cat::BibCommon->title_has_holds($e, $_); + return OpenILS::Event->new('TITLE_HAS_HOLDS', payload => $_) if $has_holds; + # we're good, delete the record + $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $_); + return $evt if $evt; + } } } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm index f9f60dcef5..db35407a1c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm @@ -724,6 +724,12 @@ sub remove_empty_objects { return OpenILS::Event->new('TITLE_LAST_COPY', payload => $vol->record ) if $aoe and not ($override->{all} || grep { $_ eq 'TITLE_LAST_COPY' } @{$override->{events}}) and not $force_delete_empty_bib; + # check for any holds on the title and alert the user before plowing ahead + if( OpenILS::Application::Cat::BibCommon->title_has_holds($editor, $vol->record) ) { + return OpenILS::Event->new('TITLE_HAS_HOLDS', payload => $vol->record ) + if not ($override->{all} || grep { $_ eq 'TITLE_HAS_HOLDS' } @{$override->{events}}) and not $force_delete_empty_bib; + } + unless($koe and not $force_delete_empty_bib) { # delete the bib record if the keep-on-empty setting is not set (and we're not otherwise forcing things, say through acq settings) my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($editor, $vol->record); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/BibCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/BibCommon.pm index 3f2cfbce60..ebbaed0043 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/BibCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/BibCommon.pm @@ -410,4 +410,27 @@ sub title_is_empty { return 1; } + +# -------------------------------------------------------------------------- +# returns true if the given title (id) has active hold requests on it +# -------------------------------------------------------------------------- +sub title_has_holds { + my($class, $editor, $rid) = @_; + + # check if $rid is an object, because may be passing the volume + # with a fleshed record in one of our callers. + $rid = $rid->id() if (ref($rid)); + + my $holds = $editor->search_action_hold_request( + [ + { fulfillment_time => undef, + cancel_time => undef, + hold_type => 'T', + target => $rid }, + { limit => 1 }, + ], { idlist => 1 }); + return 0 unless @$holds; + + return 1; # we found a hold +} 1; -- 2.11.0