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,
} 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');
}
{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}) {
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);
}
}
+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) = @_;