From 970df93ee9f1aaaad8fbc5f8796bf6130fcad54c Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Tue, 3 Nov 2015 11:21:19 -0500 Subject: [PATCH] More CancelRequestItem functionality for NCIP::ILS::Evergreen. Now, with abort transit action! The cancelrequestitem message handler can optionally abort the hold transit, if any. To activate this feature, add a section like: to your oils_ncip.xml configuration file inside the man element. See examples/oils_ncip.xml.example. Signed-off-by: Jason Stephenson --- examples/oils_ncip.xml.example | 9 +++++++ lib/NCIP/ILS/Evergreen.pm | 49 +++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/examples/oils_ncip.xml.example b/examples/oils_ncip.xml.example index 01fb8e9..95b240d 100644 --- a/examples/oils_ncip.xml.example +++ b/examples/oils_ncip.xml.example @@ -97,4 +97,13 @@ reminder to the person that edits the configuration. --> + + + diff --git a/lib/NCIP/ILS/Evergreen.pm b/lib/NCIP/ILS/Evergreen.pm index db97d70..27e10b7 100644 --- a/lib/NCIP/ILS/Evergreen.pm +++ b/lib/NCIP/ILS/Evergreen.pm @@ -1118,6 +1118,13 @@ sub cancelrequestitem { } if ($hold) { + # If there is a transit, abort it. NOTE: We do this before + # canceling to avoid negative consequences of retargeting and + # in case the reset of the hold done by the transit abort ever + # messes with cancel_time, etc. + if ($hold->transit() && $self->{abort_transit_on_hold_cancel}) { + $self->abort_transit($hold->transit()); + } my $result = $self->cancel_hold($hold); if (ref($result)) { $response->problem(_problem_from_event("Temporary Processing Failure", $result)); @@ -2351,6 +2358,31 @@ sub cancel_hold { return $r; } +=head2 abort_transit + + $result = $ils->abort_transit($transit); + +This method aborts the passed in transit and returns true or false if +it succeeded. In general, we don't care about the return value here, +but subclasses might. + +=cut + +sub abort_transit { + my $self = shift; + my $transit = shift; + my $result = $U->simplereq( + 'open-ils.circ', + 'open-ils.circ.transit.abort', + $self->{session}->{authtoken}, + {transitid => $transit->id()} + ); + if (ref($result)) { + return 0; + } + return 1; +} + =head2 create_hold_note $note = $ils->create_hold_note($hold, $title, $body); @@ -2396,9 +2428,9 @@ sub create_hold_note { $hold = $ils->find_hold_via_note($title, $body); Searches for a hold based on a note title and note body. Returns the -note if found, undef otherwise. The search is limited to unfulfilled, -uncanceled hold where the request_lib equals the NCIPServer working -org. unit. +hold, and fleshes its transit (if any), if found, undef otherwise. +The search is limited to unfulfilled, uncanceled hold where the +request_lib equals the NCIPServer working org. unit. =cut @@ -2426,7 +2458,7 @@ sub find_hold_via_note { 'open-ils.pcrud.search.ahrn', $self->{session}->{authtoken}, $search, - {flesh => 1, flesh_fields => {ahrn => ['hold']}} + {flesh => 2, flesh_fields => {ahrn => ['hold'], ahr => ['transit']}} ); if (ref($note) eq 'Fieldmapper::action::hold_request_note') { return $note->hold(); @@ -2709,6 +2741,15 @@ sub _init { my ($stat) = grep {$_->id() == $entry->{stat_cat}} @$stat_cats; push(@{$self->{stat_cat_entries}}, grep {$_->owner() =~ $re && $_->value() eq $entry->{content}} @{$stat->entries()}); } + + # Check if we should abort transits on request cancellation. We + # put this in a different variable because someone may not have + # updated their configuration since this feature was added and we + # don't want runtime errors. + $self->{abort_transit_on_hold_cancel} = 0; + if ($self->{config}->{holds} && $self->{config}->{holds}->{abort_transit_on_cancel}) { + $self->{abort_transit_on_hold_cancel} = 1; + } } # Search for holds using the user, idvalue and selection_ou. -- 2.43.2