LP#797409: Offline Transaction - Option to Skip Old Records
authorAtom Edoceo <atom@helium.edoceo.lan>
Tue, 2 Aug 2011 05:54:37 +0000 (22:54 -0700)
committerMike Rylander <mrylander@gmail.com>
Tue, 9 Aug 2011 17:18:29 +0000 (13:18 -0400)
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 <code@edoceo.com>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/offline/offline.pl
Open-ILS/src/support-scripts/test-scripts/offline.pl

index 637a885..d3f5de8 100755 (executable)
@@ -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(
index 80c2dd1..fc056af 100755 (executable)
@@ -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";