From e3c90505d2ad5d65235bb4071ed186fc37c0703e Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Thu, 4 Aug 2011 12:11:49 -0400 Subject: [PATCH] Robustify SKIP_ASSET_CHANGE functionality by skipping status_changed_time test if a barcode has been encountered in prior offline transaction within a given session. Also return the SKIP_ASSET_CHANGE event for a given barcode if a prior test resulted in SKIP_ASSET_CHANGE Signed-off-by: Jason Etheridge Signed-off-by: Mike Rylander --- Open-ILS/src/offline/offline.pl | 59 ++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/Open-ILS/src/offline/offline.pl b/Open-ILS/src/offline/offline.pl index 3ff9126f53..f7719d5741 100755 --- a/Open-ILS/src/offline/offline.pl +++ b/Open-ILS/src/offline/offline.pl @@ -26,6 +26,10 @@ my $SES = "${DB}::Session"; my $SCRIPT = "OpenILS::Utils::OfflineStore::Script"; my $user_groups; +# Used by the functionality that produces SKIP_ASSET_CHANGED events +my %seen_barcode = (); +my %skip_barcode_for_status_changed = (); + # -------------------------------------------------------------------- # Load the config # -------------------------------------------------------------------- @@ -707,7 +711,7 @@ sub ol_handle_checkout { my $barcode = $args->{barcode}; # Have to have this config option (or org setting) and a - # status_changed_time for skippage + # status_changed_time for skippage, and barcode not seen before if (( ol_get_org_setting( 'circ.offline.skip_checkout_if_newer_status_changed_time' @@ -715,18 +719,25 @@ sub ol_handle_checkout { || $config{skip_late} ) && length($c->status_changed_time()) + && ! $seen_barcode{$barcode} ) { + $seen_barcode{$barcode} = 1; 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"); + $logger->activity("offline: ol_handle_checkout: considering status_changed_time for barcode=$barcode, cts=$cts, xts=$xts"); # Asset has changed after this transaction, ignore if ($cts >= $xts) { - return OpenILS::Event->new( - 'SKIP_ASSET_CHANGED' - ); + $skip_barcode_for_status_changed{$barcode} = 1; } - # $logger->activity("offline: fetch_copy_by_barcode: " . Dumper($c->real_fields())); + } else { + $logger->activity("No skip check: barcode=$barcode seen_barcode=".$seen_barcode{$1}." status_changed_time=".$c->status_changed_time." ou_setting=".ol_get_org_setting('circ.offline.skip_checkout_if_newer_status_changed_time')); + } + if ($skip_barcode_for_status_changed{$barcode}) { + $logger->activity("offline: ol_handle_checkout: barcode=$barcode has SKIP_ASSET_CHANGED"); + return OpenILS::Event->new( + 'SKIP_ASSET_CHANGED' + ); } } @@ -763,7 +774,7 @@ sub ol_handle_renew { my $barcode = $args->{barcode}; # Have to have this config option (or org setting) and a - # status_changed_time for skippage + # status_changed_time for skippage, and barcode not seen before if (( ol_get_org_setting( 'circ.offline.skip_renew_if_newer_status_changed_time' @@ -771,17 +782,25 @@ sub ol_handle_renew { || $config{skip_late} ) && length($c->status_changed_time()) + && ! $seen_barcode{$barcode} ) { + $seen_barcode{$barcode} = 1; 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_renew: barcode=$barcode, cts=$cts, xts=$xts"); + $logger->activity("offline: ol_handle_renew: considering status_changed_time for barcode=$barcode, cts=$cts, xts=$xts"); # Asset has changed after this transaction, ignore if ($cts >= $xts) { - return OpenILS::Event->new( - 'SKIP_ASSET_CHANGED' - ); + $skip_barcode_for_status_changed{$barcode} = 1; } + } else { + $logger->activity("No skip check: barcode=$barcode seen_barcode=".$seen_barcode{$1}." status_changed_time=".$c->status_changed_time." ou_setting=".ol_get_org_setting('circ.offline.skip_renew_if_newer_status_changed_time')); + } + if ($skip_barcode_for_status_changed{$barcode}) { + $logger->activity("offline: ol_handle_renew: barcode=$barcode has SKIP_ASSET_CHANGED"); + return OpenILS::Event->new( + 'SKIP_ASSET_CHANGED' + ); } } @@ -812,7 +831,7 @@ sub ol_handle_checkin { return $e if $e; # Have to have this config option (or org setting) and a - # status_changed_time for skippage + # status_changed_time for skippage, and barcode not seen before if (( ol_get_org_setting( 'circ.offline.skip_checkin_if_newer_status_changed_time' @@ -820,17 +839,25 @@ sub ol_handle_checkin { || $config{skip_late} ) && length($c->status_changed_time()) + && ! $seen_barcode{$barcode} ) { + $seen_barcode{$barcode} = 1; 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_checkin: barcode=$barcode, cts=$cts, xts=$xts"); + $logger->activity("offline: ol_handle_checkin: considering status_changed_time for barcode=$barcode, cts=$cts, xts=$xts"); # Asset has changed after this transaction, ignore if ($cts >= $xts) { - return OpenILS::Event->new( - 'SKIP_ASSET_CHANGED' - ); + $skip_barcode_for_status_changed{$barcode} = 1; } + } else { + $logger->activity("No skip check: barcode=$barcode seen_barcode=".$seen_barcode{$1}." status_changed_time=".$c->status_changed_time." ou_setting=".ol_get_org_setting('circ.offline.skip_checkin_if_newer_status_changed_time')); + } + if ($skip_barcode_for_status_changed{$barcode}) { + $logger->activity("offline: ol_handle_checkin: barcode=$barcode has SKIP_ASSET_CHANGED"); + return OpenILS::Event->new( + 'SKIP_ASSET_CHANGED' + ); } } -- 2.11.0