[Bps-public-commit] rt-extension-assets-import-csv branch, add-separator-support, created. 1.4-6-gbd39c7f

Dave Goehrig dave at bestpractical.com
Tue Apr 4 16:17:53 EDT 2017


The branch, add-separator-support has been created
        at  bd39c7f530e1452315935b037ae73bdd401a331f (commit)

- Log -----------------------------------------------------------------
commit bd39c7f530e1452315935b037ae73bdd401a331f
Author: Dave Goehrig <dave at bestpractical.com>
Date:   Tue Apr 4 16:16:35 2017 -0400

    Add support for specifying separator charter(s)

diff --git a/lib/RT/Extension/Assets/Import/CSV.pm b/lib/RT/Extension/Assets/Import/CSV.pm
index 0b3d6fc..db6e786 100644
--- a/lib/RT/Extension/Assets/Import/CSV.pm
+++ b/lib/RT/Extension/Assets/Import/CSV.pm
@@ -20,6 +20,7 @@ sub run {
         File        => undef,
         Update      => undef,
         Insert      => undef,
+        Separator   => undef,
         @_,
     );
 
@@ -76,7 +77,7 @@ sub run {
 
     my @required_columns = ( $field2csv->{$unique ? "CF.$unique" : "id"} );
 
-    my @items = $class->parse_csv( $args{File} );
+    my @items = $class->parse_csv( $args{File}, $args{Separator} );
     unless (@items) {
         RT->Logger->warning( "No items found in file $args{File}" );
         return (0, 0, 0);
@@ -286,9 +287,10 @@ sub get_value {
 sub parse_csv {
     my $class = shift;
     my $file  = shift;
+    my $sep = shift || ',';
 
     my @rows;
-    my $csv = Text::CSV_XS->new( { binary => 1 } );
+    my $csv = Text::CSV_XS->new( { binary => 1, sep => $sep } );
 
     open my $fh, '<', $file or die "failed to read $file: $!";
     my $header = $csv->getline($fh);

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


More information about the Bps-public-commit mailing list