From 5ad1035e6ec7fe610a676f76e117d00c4279a145 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 15 Jul 2018 17:52:22 -0400 Subject: [PATCH] More back end improvements. It should actually work. Though I didn't try the previous commit, I realized that the transaction code was wrong. I also decided to make a request to open-ils.circ.transit.abort rather that do all that code "by hand." --- .../src/perlmods/lib/OpenILS/Application/Circ.pm | 49 +++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm index bbeeae5d76..22c4b779ed 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm @@ -1307,7 +1307,7 @@ sub mark_item { my( $self, $conn, $auth, $copy_id, $args ) = @_; $args ||= {}; - my $e = new_editor(authtoken=>$auth, xact =>1); + my $e = new_editor(authtoken=>$auth); return $e->die_event unless $e->checkauth; my $copy = $e->retrieve_asset_copy([ $copy_id, @@ -1359,23 +1359,7 @@ sub mark_item { } elsif ($copy->status->id() == OILS_COPY_STATUS_IN_TRANSIT) { # Items in transit need to have the transit aborted before being marked. if ($args->{handle_transit}) { - if ($e->allowed('ABORT_TRANSIT')) { - my $transit = $e->search_action_transit_copy( - { - target_copy => $copy->id, - dest_recv_time => undef, - cancel_time => undef - } - ); - if ($transit && @{$transit}) { - # Abort the transit and do not retarget holds nor commit the transaction. - # NOTE: __abort_transit should probably be moved/renamed since we're reaching in to use it. - my $r = OpenILS::Application::Circ::Transit::__abort_transit($e, $transit->[0], $copy, 1, 1); - $evt = $r if (ref $r); #__abort_transit returns 1 or an event. - } - } else { - $evt = $e->event; - } + $evt = try_abort_transit($auth, $copy_id); } else { $evt = OpenILS::Event->new('ITEM_TO_MARK_IN_TRANSIT'); } @@ -1401,12 +1385,6 @@ sub mark_item { {flesh=>1, flesh_fields=>{ahr=>['eligible_copies']}} ); - # Handle extra mark damaged charges, etc. - if ($self->api_name =~ /damaged/) { - $evt = handle_mark_damaged($e, $copy, $owning_lib, $args); - return $evt if $evt; - } - # Throw event if attempting to mark discard the only copy to fill a hold. if ($self->api_name =~ /discard/) { if (!$args->{handle_last_hold_copy}) { @@ -1421,6 +1399,16 @@ sub mark_item { return $evt if $evt; } + # Everything below here requires a transaction and there is nothing left to interfere with it. + $e->xact_begin; + + # Handle extra mark damaged charges, etc. + if ($self->api_name =~ /damaged/) { + $evt = handle_mark_damaged($e, $copy, $owning_lib, $args); + return $evt if $evt; + } + + # Mark the copy. $copy->status($stat); $copy->edit_date('now'); $copy->editor($e->requestor->id); @@ -1466,6 +1454,19 @@ sub try_checkin { } } +sub try_abort_transit { + my ($auth, $copy_id) = @_; + + my $abort = $U->simplereq( + 'open-ils.circ', + 'open-ils.circ.transit.abort', + $auth, {copyid => $copy_id} + ); + # Above returns 1 or an event. + return $abort if (ref $abort); + return undef; +} + sub handle_mark_damaged { my($e, $copy, $owning_lib, $args) = @_; -- 2.11.0