From 4ff549568a6445f145f60bd8fbb924e3d862cdb0 Mon Sep 17 00:00:00 2001 From: Atom Edoceo Date: Mon, 1 Aug 2011 22:54:37 -0700 Subject: [PATCH] LP#797409: Offline Transaction - Option to Skip Old Records Skip Copy with later Status Change Time on offline checkout import Requires the following option in offline-config.pl $main::config{skip_late} = 1; Signed-off-by: David Busby --- Open-ILS/src/offline/offline.pl | 23 +++++++++++++++++++- .../src/support-scripts/test-scripts/offline.pl | 2 + 2 files changed, 24 insertions(+), 1 deletions(-) diff --git a/Open-ILS/src/offline/offline.pl b/Open-ILS/src/offline/offline.pl index 637a885..d3f5de8 100755 --- a/Open-ILS/src/offline/offline.pl +++ b/Open-ILS/src/offline/offline.pl @@ -10,11 +10,12 @@ use OpenSRF::EX qw/:try/; use Data::Dumper; use OpenILS::Utils::Fieldmapper; use Digest::MD5 qw/md5_hex/; -use OpenSRF::Utils qw/:daemon/; +use OpenSRF::Utils qw/:daemon cleanse_ISO8601/; use OpenILS::Utils::OfflineStore; use OpenSRF::Utils::SettingsClient; use OpenSRF::Utils; use DateTime; +use DateTime::Format::ISO8601; use DBI; $DBI::trace = 1; @@ -698,8 +699,28 @@ sub ol_handle_checkout { } if( $args->{barcode} ) { + + # $c becomes the Copy + # $e possibily becomes the Exception my( $c, $e ) = $U->fetch_copy_by_barcode($args->{barcode}); return $e if $e; + + my $barcode = $args->{barcode}; + # Have to have this config option & a status_changed_time for skippage + if ( ($config{skip_late}) && (length($c->status_changed_time())) ) { + my $cts = DateTime::Format::ISO8601->parse_datetime( cleanse_ISO8601($c->status_changed_time()) )->epoch(); + my $xts = $command->{timestamp}; # Transaction Time Stamp + $logger->activity("offline: ol_handle_checkout: barcode=$barcode, cts=$cts, xts=$xts"); + + # Asset has changed after this transaction, ignore + if ($cts >= $xts) { + return OpenILS::Event->new( + 'SKIP_ASSET_CHANGED', + payload => 'The Asset has been update since this transaction, so it will be ignored' + ); + } + # $logger->activity("offline: fetch_copy_by_barcode: " . Dumper($c->real_fields())); + } } my $evt = $U->simplereq( diff --git a/Open-ILS/src/support-scripts/test-scripts/offline.pl b/Open-ILS/src/support-scripts/test-scripts/offline.pl index 80c2dd1..fc056af 100755 --- a/Open-ILS/src/support-scripts/test-scripts/offline.pl +++ b/Open-ILS/src/support-scripts/test-scripts/offline.pl @@ -81,6 +81,8 @@ sub build_script { backdate => $t1 }; + # Here we need to create an option to test the skip_late feature, ask community + $json .= OpenSRF::Utils::JSON->perl2JSON($checkout) . "\n"; $json .= OpenSRF::Utils::JSON->perl2JSON($renew) . "\n" if $renew; $json .= OpenSRF::Utils::JSON->perl2JSON($checkin) . "\n"; -- 1.7.3.4