From 1cedb423902810e9df5355ab18c7ca7e18d5391d Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Fri, 12 Aug 2016 13:41:25 -0400 Subject: [PATCH] LP#1612752 - Add cancel_time to action.transit_copy and friends. It is useful to have keep action.transit_copy rows intact when doing forensics on what happens after a staff member cancels a transit. Signed-off-by: Chris Sharp Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- Open-ILS/examples/fm_IDL.xml | 4 ++++ .../perlmods/lib/OpenILS/Application/AppUtils.pm | 4 ++-- .../src/perlmods/lib/OpenILS/Application/Booking.pm | 2 +- .../lib/OpenILS/Application/Cat/AssetCommon.pm | 7 ++++--- .../src/perlmods/lib/OpenILS/Application/Circ.pm | 2 +- .../lib/OpenILS/Application/Circ/Circulate.pm | 6 +++--- .../perlmods/lib/OpenILS/Application/Circ/Holds.pm | 11 ++++++----- .../lib/OpenILS/Application/Circ/Transit.pm | 13 ++++++++----- .../lib/OpenILS/Application/Storage/CDBI/action.pm | 6 +++--- .../OpenILS/Application/Storage/Publisher/action.pm | 4 +++- Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm | 3 ++- Open-ILS/src/sql/Pg/090.schema.action.sql | 3 ++- .../XXXX-create-transit-cancel-time-column.sql | 8 ++++++++ 13 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX-create-transit-cancel-time-column.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index b1d287eaea..eaaa780715 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2362,6 +2362,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -7397,6 +7398,7 @@ SELECT usr, + @@ -7432,6 +7434,7 @@ SELECT usr, + @@ -11133,6 +11136,7 @@ SELECT usr, + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index b24a0db6a7..bcfc81be65 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -411,7 +411,7 @@ sub fetch_hold_transit_by_hold { $transit = $self->simplereq( 'open-ils.cstore', - 'open-ils.cstore.direct.action.hold_transit_copy.search', { hold => $holdid } ); + 'open-ils.cstore.direct.action.hold_transit_copy.search', { hold => $holdid, cancel_time => undef } ); $evt = OpenILS::Event->new('ACTION_HOLD_TRANSIT_COPY_NOT_FOUND', holdid => $holdid) unless $transit; @@ -978,7 +978,7 @@ sub fetch_open_transit_by_copy { my($transit, $evt); $transit = $self->cstorereq( 'open-ils.cstore.direct.action.transit_copy.search', - { target_copy => $copyid, dest_recv_time => undef }); + { target_copy => $copyid, dest_recv_time => undef, cancel_time => undef }); $evt = OpenILS::Event->new('ACTION_TRANSIT_COPY_NOT_FOUND') unless $transit; return ($transit, $evt); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Booking.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Booking.pm index bb387312f0..37270114fa 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Booking.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Booking.pm @@ -1044,7 +1044,7 @@ sub capture_reservation { # need to transit the item ... is it already in transit? my $transit = $e->search_action_reservation_transit_copy( - {"reservation" => $res_id, "dest_recv_time" => undef} + {"reservation" => $res_id, "dest_recv_time" => undef, cancel_time => undef} )->[0]; if (!$transit) { # not yet in transit 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 a07c9be693..69e5b4b860 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm @@ -428,12 +428,13 @@ sub delete_copy { $copy->edit_date('now'); $editor->update_asset_copy($copy) or return $editor->event; - # Delete any open transits for this copy + # Cancel any open transits for this copy my $transits = $editor->search_action_transit_copy( - { target_copy=>$copy->id, dest_recv_time => undef } ); + { target_copy=>$copy->id, dest_recv_time => undef, cancel_time => undef } ); for my $t (@$transits) { - $editor->delete_action_transit_copy($t) + $t->cancel_time('now'); + $editor->update_action_transit_copy($t) or return $editor->event; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm index 4d9f881394..8f439e5997 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm @@ -1078,7 +1078,7 @@ sub copy_details { OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold; my $transit = $e->search_action_transit_copy( - { target_copy => $copy_id, dest_recv_time => undef } )->[0]; + { target_copy => $copy_id, dest_recv_time => undef, cancel_time => undef } )->[0]; # find the most recent circulation for the requested copy, # be it active, completed, or aged. diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm index e12828ccff..21b875d49c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -176,7 +176,7 @@ sub run_method { my $res_id_list = [ map { $_->id } @$resources ]; my $transit = $circulator->editor->search_action_reservation_transit_copy( [ - { target_copy => $res_id_list, dest => $circulator->circ_lib, dest_recv_time => undef }, + { target_copy => $res_id_list, dest => $circulator->circ_lib, dest_recv_time => undef, cancel_time => undef }, { order_by => { artc => 'source_send_time' }, limit => 1 } ] )->[0]; # Any transit for this barcode? @@ -2208,7 +2208,7 @@ sub check_transit_checkin_interval { # capture the transit so we don't have to fetch it again later during checkin $self->transit( $self->editor->search_action_transit_copy( - {target_copy => $self->copy->id, dest_recv_time => undef} + {target_copy => $self->copy->id, dest_recv_time => undef, cancel_time => undef} )->[0] ); @@ -2397,7 +2397,7 @@ sub do_checkin { if( $self->copy and !$self->transit ) { $self->transit( $self->editor->search_action_transit_copy( - { target_copy => $self->copy->id, dest_recv_time => undef } + { target_copy => $self->copy->id, dest_recv_time => undef, cancel_time => undef } )->[0] ); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index 024a0e671e..9c1ca72782 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -620,7 +620,7 @@ sub retrieve_holds { $hold->transit( $e->search_action_hold_transit_copy([ - {hold => $hold->id}, + {hold => $hold->id, cancel_time => undef}, {order_by => {ahtc => 'source_send_time desc'}, limit => 1}])->[0] ); @@ -807,7 +807,7 @@ sub cancel_hold { my $hid = $hold->id; $logger->warn("! canceling hold [$hid] that is in transit"); - my $transid = $e->search_action_hold_transit_copy({hold=>$hold->id},{idlist=>1})->[0]; + my $transid = $e->search_action_hold_transit_copy({hold=>$hold->id,cancel_time=>undef},{idlist=>1})->[0]; if( $transid ) { my $trans = $e->retrieve_action_transit_copy($transid); @@ -1011,7 +1011,7 @@ sub update_hold_impl { # update the transit to reflect the new pickup location my $transit = $e->search_action_hold_transit_copy( - {hold=>$hold->id, dest_recv_time => undef})->[0] + {hold=>$hold->id, cancel_time => undef, dest_recv_time => undef})->[0] or return $e->die_event; $transit->prev_dest($transit->dest); # mark the previous destination on the transit @@ -1293,6 +1293,7 @@ sub _hold_status { my $transit = $e->search_action_hold_transit_copy({ hold => $hold->id, target_copy => $copy->id, + cancel_time => undef, dest_recv_time => {'!=' => undef}, })->[0]; my $start_time = ($transit) ? $transit->dest_recv_time : $hold->capture_time; @@ -1972,7 +1973,7 @@ sub _reset_hold { # We don't want the copy to remain "in transit" $copy->status(OILS_COPY_STATUS_RESHELVING); $logger->warn("! reseting hold [$hid] that is in transit"); - my $transid = $e->search_action_hold_transit_copy({hold=>$hold->id},{idlist=>1})->[0]; + my $transid = $e->search_action_hold_transit_copy({hold=>$hold->id,cancel_time=>undef},{idlist=>1})->[0]; if( $transid ) { my $trans = $e->retrieve_action_transit_copy($transid); @@ -2049,7 +2050,7 @@ sub flesh_hold_transits { $apputils->simplereq( 'open-ils.cstore', "open-ils.cstore.direct.action.hold_transit_copy.search.atomic", - { hold => $hold->id }, + { hold => $hold->id, cancel_time => undef }, { order_by => { ahtc => 'id desc' }, limit => 1 } )->[0] ); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm index fad79239c9..f627b99c29 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Transit.pm @@ -204,7 +204,7 @@ sub abort_transit { } elsif( $copy ) { $transit = $e->search_action_transit_copy( - { target_copy => $copy->id, dest_recv_time => undef })->[0]; + { target_copy => $copy->id, dest_recv_time => undef, cancel_time => undef })->[0]; return $e->event unless $transit; } @@ -241,7 +241,9 @@ sub __abort_transit { my $holdtransit = $e->retrieve_action_hold_transit_copy($transit->id); - return $e->die_event unless $e->delete_action_transit_copy($transit); + # rather than deleting the transit row, set the cancel_time + $transit->cancel_time('now'); + return $e->die_event unless $e->update_action_transit_copy($transit); # Only change the copy status if the copy status is "In Transit." if ($copy->status == OILS_COPY_STATUS_IN_TRANSIT) { @@ -297,7 +299,7 @@ sub get_open_copy_transit { return $e->event unless $e->checkauth; return $e->event unless $e->allowed('VIEW_USER'); # XXX rely on editor perms my $t = $e->search_action_transit_copy( - { target_copy => $copyid, dest_recv_time => undef }); + { target_copy => $copyid, dest_recv_time => undef, cancel_time => undef }); return $e->event unless @$t; return $$t[0]; } @@ -316,7 +318,8 @@ sub fetch_transit_by_copy { my $t = $e->search_action_transit_copy( { target_copy => $copyid, - dest_recv_time => undef + dest_recv_time => undef, + cancel_time => undef } )->[0]; return $e->event unless $t; @@ -340,7 +343,7 @@ sub transits_by_lib { return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # eh.. basically the same permission my $order_by = {order_by => { atc => 'source_send_time' }}; - my $search = { dest_recv_time => undef }; + my $search = { dest_recv_time => undef, cancel_time => undef }; if($end_date) { if($start_date) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm index 8a33f4fae2..5a59393837 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/action.pm @@ -124,7 +124,7 @@ __PACKAGE__->table('action_hold_transit_copy'); __PACKAGE__->columns(Primary => 'id'); __PACKAGE__->columns(Essential => qw/source dest persistant_transfer target_copy source_send_time dest_recv_time prev_hop prev_dest - copy_status hold/); + cancel_time copy_status hold/); #------------------------------------------------------------------------------- @@ -134,7 +134,7 @@ __PACKAGE__->table('action_reservation_transit_copy'); __PACKAGE__->columns(Primary => 'id'); __PACKAGE__->columns(Essential => qw/source dest persistant_transfer target_copy source_send_time dest_recv_time prev_hop prev_dest - copy_status reservation/); + cancel_time copy_status reservation/); #------------------------------------------------------------------------------- @@ -144,7 +144,7 @@ __PACKAGE__->table('action_transit_copy'); __PACKAGE__->columns(Primary => 'id'); __PACKAGE__->columns(Essential => qw/source dest persistant_transfer target_copy source_send_time dest_recv_time prev_hop prev_dest - copy_status/); + cancel_time copy_status/); #------------------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm index 6e2ae2cdf7..c6118f27b7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm @@ -420,6 +420,7 @@ sub build_hold_sort_clause { COALESCE(dest_recv_time, source_send_time) AS moment FROM action.transit_copy WHERE target_copy = %d + AND cancel_time IS NULL ORDER BY moment DESC LIMIT 1 ) UNION ( SELECT @@ -504,7 +505,8 @@ sub build_hold_sort_clause { WHERE atc.target_copy = %d AND (atc.dest = %d OR atc.source = %d) AND - atc.dest_recv_time >= NOW() - (SELECT value FROM go_home_interval) + atc.dest_recv_time >= NOW() - (SELECT value FROM go_home_interval) AND + atc.cancel_time IS NULL ) AS result FROM copy_has_not_been_home ) !, $cp->id, $cp->circ_lib, $cp->circ_lib); $joins .= " JOIN copy_has_not_been_home_even_to_idle ON (true) "; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm index 2a9882517a..b32fb01cd9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Item.pm @@ -170,7 +170,8 @@ sub fetch_transit { my $transit = $e->search_action_transit_copy([ { target_copy => $copy->id, # NOT barcode ($self->id) - dest_recv_time => undef + dest_recv_time => undef, + cancel_time => undef }, { flesh => 1, diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index bed82b70cb..11ee4c3865 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -494,7 +494,8 @@ CREATE TABLE action.transit_copy ( prev_hop INT REFERENCES action.transit_copy (id) DEFERRABLE INITIALLY DEFERRED, copy_status INT NOT NULL REFERENCES config.copy_status (id) DEFERRABLE INITIALLY DEFERRED, persistant_transfer BOOL NOT NULL DEFAULT FALSE, - prev_dest INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED + prev_dest INT REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED, + cancel_time TIMESTAMP WITH TIME ZONE ); CREATE INDEX active_transit_dest_idx ON "action".transit_copy (dest); CREATE INDEX active_transit_source_idx ON "action".transit_copy (source); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX-create-transit-cancel-time-column.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX-create-transit-cancel-time-column.sql new file mode 100644 index 0000000000..e5cb0b1214 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX-create-transit-cancel-time-column.sql @@ -0,0 +1,8 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +ALTER TABLE action.transit_copy + ADD COLUMN cancel_time TIMESTAMPTZ; + +COMMIT; -- 2.43.2