From: Bernd Bleßmann Date: Sat, 24 May 2014 23:19:49 +0000 (+0200) Subject: CsvImport: Feldlängen aus den Metadaten auslesen, nicht fest codieren. X-Git-Tag: release-3.2.0beta~439 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=218aeb17c2e1259e60a0c9e216f3bb45404d68dd;p=kivitendo-erp.git CsvImport: Feldlängen aus den Metadaten auslesen, nicht fest codieren. --- diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 8c6fa73ba..681ec24de 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -465,7 +465,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 { diff --git a/SL/Controller/CsvImport/BaseMulti.pm b/SL/Controller/CsvImport/BaseMulti.pm index 31a3c3b57..7e35d9731 100644 --- a/SL/Controller/CsvImport/BaseMulti.pm +++ b/SL/Controller/CsvImport/BaseMulti.pm @@ -250,6 +250,32 @@ sub add_cvar_columns_to_displayable_columns { @{ $self->cvar_configs_by->{row_ident}->{$row_ident} }); } +sub field_lengths { + my ($self) = @_; + + my %field_lengths_by_ri = (); + + foreach my $p (@{ $self->profile }) { + my %field_lengths = map { $_->name => $_->length } grep { $_->type eq 'varchar' } @{ $p->{class}->meta->columns }; + $field_lengths_by_ri{ $p->{row_ident} } = \%field_lengths; + } + + return %field_lengths_by_ri; +} + +sub fix_field_lengths { + my ($self) = @_; + + my %field_lengths_by_ri = $self->field_lengths; + foreach my $entry (@{ $self->controller->data }) { + next unless @{ $entry->{errors} }; + my %field_lengths = %{ $field_lengths_by_ri{ $entry->{raw_data}->{datatype} } }; + map { $entry->{object}->$_(substr($entry->{object}->$_, 0, $field_lengths{$_})) if $entry->{object}->$_ } keys %field_lengths; + } + + return; +} + sub is_multiplexed { 1 } 1; diff --git a/SL/Controller/CsvImport/Contact.pm b/SL/Controller/CsvImport/Contact.pm index 2eb877e97..e653d7cb0 100644 --- a/SL/Controller/CsvImport/Contact.pm +++ b/SL/Controller/CsvImport/Contact.pm @@ -126,16 +126,6 @@ sub get_duplicate_check_fields { }; } -sub field_lengths { - return ( cp_title => 75, - cp_givenname => 75, - cp_name => 75, - cp_phone1 => 75, - cp_phone2 => 75, - cp_gender => 1, - ); -} - sub setup_displayable_columns { my ($self) = @_; diff --git a/SL/Controller/CsvImport/CustomerVendor.pm b/SL/Controller/CsvImport/CustomerVendor.pm index 946df0629..7d37904aa 100644 --- a/SL/Controller/CsvImport/CustomerVendor.pm +++ b/SL/Controller/CsvImport/CustomerVendor.pm @@ -214,26 +214,6 @@ sub save_objects { $self->SUPER::save_objects(data => $without_number); } -sub field_lengths { - return ( name => 75, - department_1 => 75, - department_2 => 75, - street => 75, - zipcode => 10, - city => 75, - country => 75, - contact => 75, - fax => 30, - account_number => 15, - bank_code => 10, - language => 5, - username => 50, - ustid => 14, - iban => 100, - bic => 100, - ); -} - sub init_profile { my ($self) = @_; diff --git a/SL/Controller/CsvImport/Shipto.pm b/SL/Controller/CsvImport/Shipto.pm index c20b574df..1d2fdd7f6 100644 --- a/SL/Controller/CsvImport/Shipto.pm +++ b/SL/Controller/CsvImport/Shipto.pm @@ -88,20 +88,6 @@ sub get_duplicate_check_fields { }; } -sub field_lengths { - return ( shiptoname => 75, - shiptodepartment_1 => 75, - shiptodepartment_2 => 75, - shiptostreet => 75, - shiptozipcode => 75, - shiptocity => 75, - shiptocountry => 75, - shiptocontact => 75, - shiptophone => 30, - shiptofax => 30, - ); -} - sub init_profile { my ($self) = @_;