X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FBase.pm;h=c94f1bac3337ce364d3fa49775debcf2537786fb;hb=7ed4b336b89b861479a1fc2670b9456334b0d1be;hp=9993975025e6ac274366bc0fd5ab43139f4dcdb7;hpb=7c24fbc300140117e2011e72b6f5abd0d7b1713e;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 999397502..c94f1bac3 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -2,6 +2,7 @@ package SL::Controller::CsvImport::Base; use strict; +use English qw(-no_match_vars); use List::MoreUtils qw(pairwise any); use SL::Helper::Csv; @@ -24,7 +25,7 @@ use Rose::Object::MakeMethods::Generic sub run { my ($self, %params) = @_; - $self->test_run($params{test_run}); + $self->test_run($params{test}); $self->controller->track_progress(phase => 'parsing csv', progress => 0); @@ -221,15 +222,29 @@ sub handle_cvars { bool => 'bool_value' ); my @cvars; + my %changed_cvars; foreach my $config (@{ $self->all_cvar_configs }) { 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 => ''); + my $new_cvar = SL::DB::CustomVariable->new(config_id => $config->id, $column => $value, sub_module => ''); + + push @cvars, $new_cvar; + $changed_cvars{$config->name} = $new_cvar; } - $entry->{object}->custom_variables(\@cvars); + # merge existing with new cvars. swap every existing with the imported one, push the rest + if (@cvars) { + my @orig_cvars = ($entry->{object_to_save} || $entry->{object})->custom_variables; + for (@orig_cvars) { + $_ = $changed_cvars{ $_->config->name } if $changed_cvars{ $_->config->name }; + delete $changed_cvars{ $_->config->name }; + } + push @orig_cvars, values %changed_cvars; + + $entry->{object}->custom_variables(\@orig_cvars); + } } sub init_profile { @@ -447,9 +462,9 @@ sub save_objects { my $ret; if (!eval { $ret = $object->save(cascade => !!$self->save_with_cascade()); 1 }) { - push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $@); + push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $EVAL_ERROR); } elsif ( !$ret ) { - push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $entry->{object}->db->error); + push @{ $entry->{errors} }, $::locale->text('Error when saving: #1', $object->db->error); } else { $self->_save_history($object); $self->controller->num_imported($self->controller->num_imported + 1); @@ -465,7 +480,9 @@ sub save_objects { } sub field_lengths { - return (); + my ($self) = @_; + + return map { $_->name => $_->length } grep { $_->type eq 'varchar' } @{$self->class->meta->columns}; } sub fix_field_lengths {