[freeside-commits] branch master updated. a21d07037590cccd5ac5c572f5d28f062c622968

Jonathan Prykop jonathan at 420.am
Fri May 13 20:03:47 PDT 2016


The branch, master has been updated
       via  a21d07037590cccd5ac5c572f5d28f062c622968 (commit)
      from  091e39d6952f3ae61b4993b19643fec6e4a52979 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a21d07037590cccd5ac5c572f5d28f062c622968
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Fri May 13 22:02:57 2016 -0500

    RT#39913: Conexiant API [distinguish all rows previously imported from truly empty files]

diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index a117b74..7f76d99 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -2152,6 +2152,7 @@ sub batch_import {
   #my $job     = $param->{job};
   my $line;
   my $imported = 0;
+  my $unique_skip = 0; #lines skipped because they're already in the system
   my( $last, $min_sec ) = ( time, 5 ); #progressbar foo
   while (1) {
 
@@ -2254,6 +2255,7 @@ sub batch_import {
       }
       last if exists( $param->{skiprow} );
     }
+    $unique_skip++ if $param->{unique_skip}; #line is already in the system
     next if exists( $param->{skiprow} );
 
     if ( $preinsert_callback ) {
@@ -2299,7 +2301,8 @@ sub batch_import {
 
   unless ( $imported || $param->{empty_ok} ) {
     $dbh->rollback if $oldAutoCommit;
-    return "Empty file!";
+    # freeside-cdr-conexiant-import is sensitive to the text of this message
+    return $unique_skip ? "All records in file were previously imported" : "Empty file!";
   }
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
diff --git a/FS/FS/cdr/conexiant.pm b/FS/FS/cdr/conexiant.pm
index 852c2f6..4ee3f14 100644
--- a/FS/FS/cdr/conexiant.pm
+++ b/FS/FS/cdr/conexiant.pm
@@ -15,9 +15,10 @@ use FS::cdr qw( _cdr_date_parser_maker _cdr_min_parser_maker );
     skip(3),               #LookupError,Direction,LegType
     sub {                  #CallId
       my($cdr,$value,$conf,$param) = @_;
+      #filter out already-imported cdrs here
       if (qsearchs('cdr',{'uniqueid' => $value})) {
         $param->{'skiprow'} = 1;
-        $param->{'empty_ok'} = 1;
+        $param->{'unique_skip'} = 1; #tell batch_import why we're skipping
       } else {
         $cdr->uniqueid($value);
       }
diff --git a/FS/bin/freeside-cdr-conexiant-import b/FS/bin/freeside-cdr-conexiant-import
index a79477c..f2b4691 100755
--- a/FS/bin/freeside-cdr-conexiant-import
+++ b/FS/bin/freeside-cdr-conexiant-import
@@ -68,13 +68,11 @@ my $ua  = LWP::UserAgent->new;
 # Download files are created automatically at regular frequent intervals,
 # but they contain overlapping data.
 #
-# FS::cdr::conexiant automatically skips previously imported cdrs,
-# though if it does so for all records in a file, 
-# then batch_import thinks the file is empty
+# FS::cdr::conexiant automatically skips previously imported cdrs
 foreach my $file (@$files) {
   next unless $file->{'BilledCallsOnly'};
   my $cdrbatch = 'conexiant-' . $file->{'Identifier'};
-  # files that were "empty" will unfortunately be re-downloaded,
+  # files that contained no new records will unfortunately be re-downloaded,
   # but the alternative is to leave an excess of empty batches in system,
   # and re-downloading is harmless (all files expire after 48 hours anyway)
   if (qsearchs('cdr_batch',{ 'cdrbatch' => $cdrbatch })) {
@@ -113,6 +111,9 @@ foreach my $file (@$files) {
     'format'          => 'conexiant'
   });
   if ($error eq 'Empty file!') {
+    print "File contains no records\n" if $verbose;
+    $error = '';
+  } elsif ($error eq "All records in file were previously imported") {
     print "File contains no new cdrs, no batch created\n" if $verbose;
     $error = '';
   } elsif ($verbose && !$error) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Record.pm                      |    5 ++++-
 FS/FS/cdr/conexiant.pm               |    3 ++-
 FS/bin/freeside-cdr-conexiant-import |    9 +++++----
 3 files changed, 11 insertions(+), 6 deletions(-)




More information about the freeside-commits mailing list