X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FContact.pm;h=5ca2ae848dcef9ae2ff801ca3f5671fdd80a4843;hb=b16b33c220a567bf8a8b998ff69d44d380b0a181;hp=b2657fb4488d43c4a63bf909d48e7a5026a977a0;hpb=78c5d01b4d391a1f500c43d3a769711fc8b49ca3;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Contact.pm b/SL/Controller/CsvImport/Contact.pm index b2657fb44..5ca2ae848 100644 --- a/SL/Controller/CsvImport/Contact.pm +++ b/SL/Controller/CsvImport/Contact.pm @@ -24,20 +24,64 @@ sub init_all_cvar_configs { return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'Contacts' ]); } +sub force_allow_columns { + return qw(cp_id); +} + sub check_objects { my ($self) = @_; $self->controller->track_progress(phase => 'building data', progress => 0); - my $i; - my $num_data = scalar @{ $self->controller->data }; + my $i = 0; + my $num_data = scalar @{ $self->controller->data }; + my $update_policy = $self->controller->profile->get('update_policy') || 'update_existing'; + my %contacts_by_id = map { ( $_->cp_id => $_ ) } @{ $self->existing_objects }; + my $methods = $self->controller->headers->{methods}; + my %used_methods = map { ( $_ => 1 ) } @{ $methods }; + foreach my $entry (@{ $self->controller->data }) { $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0; + my $object = $entry->{object}; + if ($object->cp_id) { + my $existing_contact = $contacts_by_id{ $object->cp_id }; + if (!$existing_contact) { + $contacts_by_id{ $object->cp_id } = $object; + + } elsif ($update_policy eq 'skip') { + push(@{ $entry->{errors} }, $::locale->text('Skipping due to existing entry in database')); + next; + + } elsif ($update_policy eq 'update_existing') { + # Update existing customer/vendor records. + $entry->{object_to_save} = $existing_contact; + + $object->cp_cv_id($existing_contact->cp_cv_id); + + foreach (qw(cp_name cp_gender)) { + $object->$_($existing_contact->$_) if !$object->$_; + } + + $existing_contact->$_( $entry->{object}->$_ ) for @{ $methods }; + + push @{ $entry->{information} }, $::locale->text('Updating existing entry in database'); + + } else { + $object->cp_id(undef); + } + } + $self->check_name($entry); $self->check_vc($entry, 'cp_cv_id'); $self->check_gender($entry); $self->handle_cvars($entry); + + my @cleaned_fields = $self->clean_fields(qr{[\r\n]}, $object, qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax + cp_privatphone cp_privatemail cp_abteilung cp_street cp_zipcode cp_city cp_position)); + + push @{ $entry->{information} }, $::locale->text('Illegal characters have been removed from the following fields: #1', join(', ', @cleaned_fields)) + if @cleaned_fields; } continue { $i++; } @@ -105,6 +149,7 @@ sub setup_displayable_columns { { name => 'cp_fax', description => $::locale->text('Fax') }, { name => 'cp_gender', description => $::locale->text('Gender') }, { name => 'cp_givenname', description => $::locale->text('Given Name') }, + { name => 'cp_id', description => $::locale->text('Database ID') }, { name => 'cp_mobile1', description => $::locale->text('Mobile1') }, { name => 'cp_mobile2', description => $::locale->text('Mobile2') }, { name => 'cp_name', description => $::locale->text('Name') }, @@ -116,7 +161,7 @@ sub setup_displayable_columns { { name => 'cp_satfax', description => $::locale->text('Sat. Fax') }, { name => 'cp_satphone', description => $::locale->text('Sat. Phone') }, { name => 'cp_title', description => $::locale->text('Title') }, - { name => 'cp_position', description => $::locale->text('Function/Position') }, + { name => 'cp_position', description => $::locale->text('Function/position') }, { name => 'customer', description => $::locale->text('Customer (name)') }, { name => 'customernumber', description => $::locale->text('Customer Number') },