From 20502484e2e87cbc65476038ae4c3677bf7950f6 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 6 Jun 2011 14:26:42 -0400 Subject: [PATCH] Cancel volume/copy holds on delete Cancel all holds that directly target a copy or volume when the copy/volume is being deleted. Sends async message to A/T for each hold to create and run the necessary events (e.g. send cancellation notices). Signed-off-by: Bill Erickson Signed-off-by: Jason Etheridge --- .../lib/OpenILS/Application/Cat/AssetCommon.pm | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) 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 5ac2a1d0af..11ecdfc3b3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm @@ -347,6 +347,9 @@ sub delete_copy { or return $editor->event; } + my $evt = $class->cancel_copy_holds($editor, $copy); + return $evt if $evt; + $class->check_hold_retarget($editor, $copy, undef, $retarget_holds); return undef if $skip_empty_cleanup; @@ -355,6 +358,62 @@ sub delete_copy { } +# deletes all holds that specifically target the deleted copy +sub cancel_copy_holds { + my($class, $editor, $copy) = @_; + + my $holds = $editor->search_action_hold_request({ + target => $copy->id, + hold_type => [qw/C R F/], + cancel_time => undef, + fulfillment_time => undef + }); + + return $class->cancel_hold_list($editor, $holds); +} + +# deletes all holds that specifically target the deleted volume +sub cancel_volume_holds { + my($class, $editor, $volume) = @_; + + my $holds = $editor->search_action_hold_request({ + target => $volume->id, + hold_type => 'V', + cancel_time => undef, + fulfillment_time => undef + }); + + return $class->cancel_hold_list($editor, $holds); +} + +sub cancel_hold_list { + my($class, $editor, $holds) = @_; + + for my $hold (@$holds) { + + $hold->cancel_time('now'); + $hold->cancel_cause(1); # un-targeted expiration. Do we need an alternate "target deleted" cause? + $editor->update_action_hold_request($hold) or return $editor->die_event; + + # delete the copy maps. + my $maps = $editor->search_action_hold_copy_map({hold => $hold->id}); + for(@$maps) { + $editor->delete_action_hold_copy_map($_) + or return $editor->die_event; + } + + # tell A/T the hold was cancelled. Don't wait for a response.. + my $at_ses = OpenSRF::AppSession->create('open-ils.trigger'); + $at_ses->request( + 'open-ils.trigger.event.autocreate', + 'hold_request.cancel.expire_no_target', + $hold, $hold->pickup_lib); + } + + return undef; +} + + sub create_volume { my($class, $override, $editor, $vol) = @_; @@ -548,6 +607,9 @@ sub delete_volume { $vol->editor($editor->requestor->id); $editor->update_asset_call_number($vol) or return $editor->die_event; + $evt = $class->cancel_volume_holds($editor, $vol); + return $evt if $evt; + # handle the case where this is the last volume on the record return $class->remove_empty_objects($editor, $override, $vol); } -- 2.11.0