From 320664922d387971c50ff1070abc2b73050a024f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 22 Mar 2017 18:04:05 +0100 Subject: [PATCH] =?utf8?q?CsvImport=20Multiplex/Auftr=C3=A4ge:=20Auch=20ni?= =?utf8?q?cht=20angegebene=20CVars=20im=20Objekt=20speichern.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/CsvImport/BaseMulti.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/SL/Controller/CsvImport/BaseMulti.pm b/SL/Controller/CsvImport/BaseMulti.pm index ad8403994..7ab7062c0 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; @@ -167,13 +167,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 +299,3 @@ sub fix_field_lengths { sub is_multiplexed { 1 } 1; - -- 2.20.1