[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 77120fa89e7e76c0f85a4245d52d733fcf489a2a

Ivan ivan at 420.am
Tue Aug 7 23:08:58 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  77120fa89e7e76c0f85a4245d52d733fcf489a2a (commit)
      from  3c183289ab4a1e8398913487696d33a7ca21fe0a (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 77120fa89e7e76c0f85a4245d52d733fcf489a2a
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Aug 7 23:08:56 2012 -0700

    ignore extra columns in CCH diff (bad data from last update?), RT#18817

diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm
index 3fdaa1e..a5a623d 100644
--- a/FS/FS/tax_rate.pm
+++ b/FS/FS/tax_rate.pm
@@ -10,6 +10,7 @@ use DateTime::Format::Strptime;
 use Storable qw( thaw nfreeze );
 use IO::File;
 use File::Temp;
+use Text::CSV_XS;
 use LWP::UserAgent;
 use HTTP::Request;
 use HTTP::Response;
@@ -637,6 +638,7 @@ sub batch_import {
   $count *=2;
 
   if ( $format eq 'cch' || $format eq 'cch-update' ) {
+    #false laziness w/below (sub _perform_cch_diff)
     @fields = qw( geocode inoutcity inoutlocal tax location taxbase taxmax
                   excessrate effective_date taxauth taxtype taxcat taxname
                   usetax useexcessrate fee unittype feemax maxtype passflag
@@ -715,9 +717,6 @@ sub batch_import {
     die "unknown format $format";
   }
 
-  eval "use Text::CSV_XS;";
-  die $@ if $@;
-
   my $csv = new Text::CSV_XS;
 
   my $imported = 0;
@@ -759,12 +758,10 @@ sub batch_import {
       $tax_rate{$field} = shift @columns; 
     }
 
-    #ignoring extra columns (bad data from last update?) and seeing if that
-    # allows the upgrade to proceed
-    #if ( scalar( @columns ) ) {
-    #  $dbh->rollback if $oldAutoCommit;
-    #  return "Unexpected trailing columns in line (wrong format?) importing tax_rate: $line";
-    #}
+    if ( scalar( @columns ) ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "Unexpected trailing columns in line (wrong format?) importing tax_rate: $line";
+    }
 
     my $error = &{$hook}(\%tax_rate);
     if ( $error ) {
@@ -1118,8 +1115,26 @@ sub _perform_cch_diff {
   }
   close $newcsvfh;
 
-  for (keys %oldlines) {
-    print $dfh $_, ',"D"', "\n" if $oldlines{$_};
+  #false laziness w/above (sub batch_import)
+  my @fields = qw( geocode inoutcity inoutlocal tax location taxbase taxmax
+                   excessrate effective_date taxauth taxtype taxcat taxname
+                   usetax useexcessrate fee unittype feemax maxtype passflag
+                   passtype basetype );
+  my $numfields = scalar(@fields);
+
+  my $csv = new Text::CSV_XS { 'always_quote' => 1 };
+
+  for my $line (grep $oldlines{$_}, keys %oldlines) {
+
+    $csv->parse($line) or do {
+      #$dbh->rollback if $oldAutoCommit;
+      die "can't parse: ". $csv->error_input();
+    };
+    my @columns = $csv->fields();
+    
+    $csv->combine( splice(@columns, 0, $numfields) );
+
+    print $dfh $csv->string, ',"D"', "\n";
   }
 
   close $dfh;
@@ -1173,9 +1188,6 @@ sub _cch_fetch_and_unzip {
 sub _cch_extract_csv_from_dbf {
   my ( $job, $dir, $name ) = @_;
 
-  eval "use Text::CSV_XS;";
-  die $@ if $@;
-
   eval "use XBase;";
   die $@ if $@;
 

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

Summary of changes:
 FS/FS/tax_rate.pm |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)




More information about the freeside-commits mailing list