X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FBaseMulti.pm;h=b97539489152794c738e72515cdac0db8d028305;hb=37f2ab4d240926b9cb0b09090cff24c5ff63c5fd;hp=ad84039943ae7e3a8dcd271d26679107b4bbfde4;hpb=d88c278c29cd4ea6963062a3af6f85694e15aa7e;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/BaseMulti.pm b/SL/Controller/CsvImport/BaseMulti.pm index ad8403994..b97539489 100644 --- a/SL/Controller/CsvImport/BaseMulti.pm +++ b/SL/Controller/CsvImport/BaseMulti.pm @@ -2,7 +2,7 @@ package SL::Controller::CsvImport::BaseMulti; use strict; -use List::MoreUtils qw(pairwise); +use List::MoreUtils qw(pairwise firstidx); use SL::Helper::Csv; @@ -22,7 +22,7 @@ sub run { my $profile = $self->profile; - $self->csv(SL::Helper::Csv->new(file => $self->file->file_name, + $self->csv(SL::Helper::Csv->new(file => ('SCALAR' eq ref $self->file)? $self->file: $self->file->file_name, encoding => $self->controller->profile->get('charset'), profile => $profile, ignore_unknown_columns => 1, @@ -158,6 +158,8 @@ sub init_cvar_columns_by { sub handle_cvars { my ($self, $entry, %params) = @_; + return if @{ $entry->{errors} }; + my %type_to_column = ( text => 'text_value', textfield => 'text_value', select => 'text_value', @@ -167,13 +169,21 @@ sub handle_cvars { bool => 'bool_value' ); $params{sub_module} ||= ''; + + # autovivify all cvars (cvars_by_config will do that for us) my @cvars; + @cvars = @{ $entry->{object}->cvars_by_config } if $entry->{object}->can('cvars_by_config'); + foreach my $config (@{ $self->cvar_configs_by->{row_ident}->{$entry->{raw_data}->{datatype}} }) { next unless exists $entry->{raw_data}->{ "cvar_" . $config->name }; my $value = $entry->{raw_data}->{ "cvar_" . $config->name }; my $column = $type_to_column{ $config->type } || die "Program logic error: unknown custom variable storage type"; - push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value, sub_module => $params{sub_module}); + my $cvar = SL::DB::CustomVariable->new(config_id => $config->id, $column => $value, sub_module => $params{sub_module}); + + # replace autovivified cvar by new one + my $idx = firstidx { $_->config_id == $config->id } @cvars; + $cvars[$idx] = $cvar if -1 != $idx; } $entry->{object}->custom_variables(\@cvars) if @cvars; @@ -291,4 +301,3 @@ sub fix_field_lengths { sub is_multiplexed { 1 } 1; -