X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FBase.pm;h=1aaec79c9555cc7681596f4d4f8365f19c613aa3;hb=af8f0a39dd0739e1ec5acdeee46bc28cd891de69;hp=663be5eb8b8e7beb1ebf78b51578e3f315c307a7;hpb=6410ae9fc53e8501b21038c41005e39831020f5f;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 663be5eb8..1aaec79c9 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -288,14 +288,19 @@ sub check_vc { sub handle_cvars { my ($self, $entry) = @_; + my $object = $entry->{object_to_save} || $entry->{object}; + return unless $object->can('cvars_by_config'); + my %type_to_column = ( text => 'text_value', textfield => 'text_value', + htmlfield => 'text_value', select => 'text_value', date => 'timestamp_value_as_date', timestamp => 'timestamp_value_as_date', number => 'number_value_as_number', bool => 'bool_value' ); + # autovivify all cvars (cvars_by_config will do that for us) my @cvars; my %changed_cvars; foreach my $config (@{ $self->all_cvar_configs }) { @@ -310,16 +315,13 @@ sub handle_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); + my @orig_cvars = @{ $object->cvars_by_config }; + for (@orig_cvars) { + $_ = $changed_cvars{ $_->config->name } if $changed_cvars{ $_->config->name }; + delete $changed_cvars{ $_->config->name }; } + push @orig_cvars, values %changed_cvars; + $object->custom_variables(\@orig_cvars); } sub init_profile { @@ -538,9 +540,11 @@ sub save_objects { SL::DB->client->with_transaction(sub { foreach my $entry_index ($chunk_size * $chunk .. min( $last_index, $chunk_size * ($chunk + 1) - 1 )) { my $entry = $data->[$entry_index]; - next if @{ $entry->{errors} }; my $object = $entry->{object_to_save} || $entry->{object}; + $self->save_additions_always($object); + + next if @{ $entry->{errors} }; my $ret; if (!eval { $ret = $object->save(cascade => !!$self->save_with_cascade()); 1 }) { @@ -601,6 +605,18 @@ sub save_additions { return; } +sub save_additions_always { + my ($self, $object) = @_; + + # Can be overridden by derived specialized importer classes to save + # additional tables always. + # This sub is called before the object is saved. Therefore this + # hook will always be executed whether or not the import entry can be saved successfully. + + return; +} + + sub _save_history { my ($self, $object) = @_;