Robustify SKIP_ASSET_CHANGE functionality
authorJason Etheridge <jason@esilibrary.com>
Thu, 4 Aug 2011 16:11:49 +0000 (12:11 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 9 Aug 2011 17:18:43 +0000 (13:18 -0400)
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 <jason@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/offline/offline.pl

index 3ff9126..f7719d5 100755 (executable)
@@ -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'
+            );
         }
     }