X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/3f924c0fc876c2133e5ba22f25a45a484885ee0b..64bfffdeef8d0e47a668041b97bfe59ed7efe6f9:/SL/Controller/CsvImport/BaseMulti.pm diff --git a/SL/Controller/CsvImport/BaseMulti.pm b/SL/Controller/CsvImport/BaseMulti.pm index 5f5e337bf..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; @@ -188,7 +196,7 @@ sub init_profile { my %unwanted = map { ( $_ => 1 ) } (qw(itime mtime), map { $_->name } @{ $class->meta->primary_key_columns }); - # TODO: execeptions for AccTransaction and Invoice wh + # TODO: exceptions for AccTransaction and Invoice wh if ( $class =~ m/^SL::DB::AccTransaction/ ) { my %unwanted_acc_trans = map { ( $_ => 1 ) } (qw(acc_trans_id trans_id cleared fx_transaction ob_transaction cb_transaction itime mtime chart_link tax_id description gldate memo source transdate), map { $_->name } @{ $class->meta->primary_key_columns }); @unwanted{keys %unwanted_acc_trans} = values %unwanted_acc_trans; @@ -291,4 +299,3 @@ sub fix_field_lengths { sub is_multiplexed { 1 } 1; -