X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FCsv.pm;h=e9fd45c6a24106cc850442f86d692e22ddb4969c;hb=e45da3008937139edf0078e6b157f1e9bf5c46f0;hp=c58575afe360fccec7d7faa49ee224227e9ee0b0;hpb=265fa6a6f42909e4e27870a1dd838c4570ba61a8;p=kivitendo-erp.git diff --git a/SL/Helper/Csv.pm b/SL/Helper/Csv.pm index c58575afe..e9fd45c6a 100644 --- a/SL/Helper/Csv.pm +++ b/SL/Helper/Csv.pm @@ -158,10 +158,11 @@ sub _check_header { foreach my $p_num (0..$n_header - 1) { my $h = $self->_csv->getline($self->_io); + my ($code, $string, $position, $record, $field) = $self->_csv->error_diag; + $self->_push_error([ $self->_csv->error_input, - $self->_csv->error_diag, - 0, + $code, $string, $position, $record // 0, ]) unless $h; if ($self->is_multiplexed) { @@ -238,6 +239,10 @@ sub _check_multiplex_datatype_position { } } +sub _is_empty_row { + return !!all { !$_ } @{$_[0]}; +} + sub _parse_data { my ($self, %params) = @_; my (@data, @errors); @@ -245,6 +250,7 @@ sub _parse_data { while (1) { my $row = $self->_csv->getline($self->_io); if ($row) { + next if _is_empty_row($row); my $header = $self->_header_by_row($row); if (!$header) { push @errors, [ @@ -259,19 +265,15 @@ sub _parse_data { push @data, \%hr; } else { last if $self->_csv->eof; + # Text::CSV_XS 0.89 added record number to error_diag - if (qv(Text::CSV_XS->VERSION) >= qv('0.89')) { - push @errors, [ - $self->_csv->error_input, - $self->_csv->error_diag, - ]; - } else { - push @errors, [ - $self->_csv->error_input, - $self->_csv->error_diag, - $self->_io->input_line_number, - ]; - } + my ($code, $string, $position, $record, $field) = $self->_csv->error_diag; + + push @errors, [ + $self->_csv->error_input, + $code, $string, $position, + $record // $self->_io->input_line_number, + ]; } last if $self->_csv->eof; } @@ -500,7 +502,7 @@ See section L for information on this topic. =item C -If set, the import will ignore unkown header columns. Useful for lazy imports, +If set, the import will ignore unknown header columns. Useful for lazy imports, but deactivated by default. =item C