From 0297cac9a9ee9ada4fa4fd70123a24e0fa13aac9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 1 Mar 2011 15:06:34 +0100 Subject: [PATCH] =?utf8?q?L=C3=A4ngenbeschr=C3=A4nkung=20bei=20bestimmten?= =?utf8?q?=20Feldern?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/CsvImport.pm | 3 ++- SL/Controller/CsvImport/Base.pm | 19 +++++++++++--- SL/Controller/CsvImport/CustomerVendor.pm | 32 +++++++++++++++++++---- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 806429d7d..7717e2cee 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -142,7 +142,8 @@ sub test_and_import { } my $worker = $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file) - : die "Program logic error"; + : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new( controller => $self, file => $file) + : die "Program logic error"; $worker->run; $worker->save_objects if !$params{test}; diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 9dc9168fb..175392240 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -15,8 +15,6 @@ use Rose::Object::MakeMethods::Generic sub run { my ($self) = @_; - $::lxdebug->dump(0, "file", $self->file); - $::lxdebug->dump(0, "profile", $self->controller->profile); my $profile = $self->profile; $self->csv(SL::Helper::Csv->new(file => $self->file->file_name, encoding => $self->controller->profile->get('charset'), @@ -29,8 +27,6 @@ sub run { $self->controller->errors([ $self->csv->errors ]) if $self->csv->errors; - $::lxdebug->dump(0, "err", $self->csv->errors); - return unless $self->csv->header; my $headers = { headers => [ grep { $profile->{$_} } @{ $self->csv->header } ] }; @@ -41,6 +37,7 @@ sub run { $self->check_objects; $self->check_duplicates if $self->controller->profile->get('duplicates', 'no_check') ne 'no_check'; + $self->fix_field_lenghts; } sub init_profile { @@ -101,4 +98,18 @@ sub save_objects { } } +sub field_lengths { + return (); +} + +sub fix_field_lenghts { + my ($self) = @_; + + my %field_lengths = $self->field_lengths; + foreach my $entry (@{ $self->controller->data }) { + next unless @{ $entry->{errors} }; + map { $entry->{object}->$_(substr($entry->{object}->$_, 0, $field_lengths{$_})) if $entry->{object}->$_ } keys %field_lengths; + } +} + 1; diff --git a/SL/Controller/CsvImport/CustomerVendor.pm b/SL/Controller/CsvImport/CustomerVendor.pm index 1fb29cc29..9cb115745 100644 --- a/SL/Controller/CsvImport/CustomerVendor.pm +++ b/SL/Controller/CsvImport/CustomerVendor.pm @@ -8,16 +8,17 @@ use parent qw(SL::Controller::CsvImport::Base); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(table) ], + 'scalar --get_set_init' => [ qw(table) ], ); -sub run { +sub init_table { my ($self) = @_; - $self->table($self->controller->profile->get('table') eq 'customer' ? 'customer' : 'vendor'); - $self->class('SL::DB::' . ucfirst($self->table)); +} - $self->SUPER::run; +sub init_class { + my ($self) = @_; + $self->class('SL::DB::' . ucfirst($self->table)); } sub check_objects { @@ -81,4 +82,25 @@ 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, + phone => 30, + fax => 30, + account_number => 15, + bank_code => 10, + language => 5, + username => 50, + ustid => 14, + iban => 100, + bic => 100, + ); +} + 1; -- 2.20.1