}
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};
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'),
$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 } ] };
$self->check_objects;
$self->check_duplicates if $self->controller->profile->get('duplicates', 'no_check') ne 'no_check';
+ $self->fix_field_lenghts;
}
sub init_profile {
}
}
+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;
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 {
$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;