From 218aeb17c2e1259e60a0c9e216f3bb45404d68dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Sun, 25 May 2014 01:19:49 +0200 Subject: [PATCH] =?utf8?q?CsvImport:=20Feldl=C3=A4ngen=20aus=20den=20Metad?= =?utf8?q?aten=20auslesen,=20nicht=20fest=20codieren.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/CsvImport/Base.pm | 4 +++- SL/Controller/CsvImport/BaseMulti.pm | 26 +++++++++++++++++++++++ SL/Controller/CsvImport/Contact.pm | 10 --------- SL/Controller/CsvImport/CustomerVendor.pm | 20 ----------------- SL/Controller/CsvImport/Shipto.pm | 14 ------------ 5 files changed, 29 insertions(+), 45 deletions(-) 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) = @_; -- 2.20.1