CsvImport Mapping: header mit helper parsen
authorSven Schöling <s.schoeling@linet-services.de>
Thu, 16 Jun 2016 15:34:57 +0000 (17:34 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 16 Jun 2016 16:17:25 +0000 (18:17 +0200)
sonst gibt es wieder die gleichen Probleme mit UTF-BOM

SL/Controller/CsvImport.pm

index e53917e..99f51c9 100644 (file)
@@ -239,19 +239,13 @@ sub action_add_mapping_from_upload {
     return;
   }
 
-  my $csv = Text::CSV_XS->new({
-    binary      => 1,
-    sep_char    => $self->profile->get('sep_char'),
-    quote_char  => $self->profile->get('quote_char'),
-    escape_char => $self->profile->get('escape_char'),
-  });
-
-  my $header = $csv->getline($file->fh) or do {
-    $self->js
-      ->flash('error', t8('No header found'))
-      ->render;
-    return;
-  };
+  my $csv = SL::Helper::Csv->new(
+    file => $file->file_name,
+    map { $_ => $self->profile->get($_) } qw(sep_char escape_char quote_char),
+  );
+
+  $csv->_open_file;
+  my $header = $csv->check_header;
 
   for my $field (@$header) {
     next if $self->mappings_for_profile->{$field};