Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0297cac9

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 0297cac9a9ee9ada4fa4fd70123a24e0fa13aac9
  • Vorgänger 4970b5b2
  • Nachfolger efc63086

Längenbeschränkung bei bestimmten Feldern

Unterschiede anzeigen:

SL/Controller/CsvImport.pm
142 142
  }
143 143

  
144 144
  my $worker = $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file)
145
    :                                                 die "Program logic error";
145
             : $self->{type} eq 'contacts'          ? SL::Controller::CsvImport::Contact->new(       controller => $self, file => $file)
146
             :                                        die "Program logic error";
146 147

  
147 148
  $worker->run;
148 149
  $worker->save_objects if !$params{test};
SL/Controller/CsvImport/Base.pm
15 15
sub run {
16 16
  my ($self) = @_;
17 17

  
18
  $::lxdebug->dump(0, "file", $self->file);
19
  $::lxdebug->dump(0, "profile", $self->controller->profile);
20 18
  my $profile = $self->profile;
21 19
  $self->csv(SL::Helper::Csv->new(file                   => $self->file->file_name,
22 20
                                  encoding               => $self->controller->profile->get('charset'),
......
29 27

  
30 28
  $self->controller->errors([ $self->csv->errors ]) if $self->csv->errors;
31 29

  
32
  $::lxdebug->dump(0, "err", $self->csv->errors);
33

  
34 30
  return unless $self->csv->header;
35 31

  
36 32
  my $headers         = { headers => [ grep { $profile->{$_} } @{ $self->csv->header } ] };
......
41 37

  
42 38
  $self->check_objects;
43 39
  $self->check_duplicates if $self->controller->profile->get('duplicates', 'no_check') ne 'no_check';
40
  $self->fix_field_lenghts;
44 41
}
45 42

  
46 43
sub init_profile {
......
101 98
  }
102 99
}
103 100

  
101
sub field_lengths {
102
  return ();
103
}
104

  
105
sub fix_field_lenghts {
106
  my ($self) = @_;
107

  
108
  my %field_lengths = $self->field_lengths;
109
  foreach my $entry (@{ $self->controller->data }) {
110
    next unless @{ $entry->{errors} };
111
    map { $entry->{object}->$_(substr($entry->{object}->$_, 0, $field_lengths{$_})) if $entry->{object}->$_ } keys %field_lengths;
112
  }
113
}
114

  
104 115
1;
SL/Controller/CsvImport/CustomerVendor.pm
8 8

  
9 9
use Rose::Object::MakeMethods::Generic
10 10
(
11
 scalar => [ qw(table) ],
11
 'scalar --get_set_init' => [ qw(table) ],
12 12
);
13 13

  
14
sub run {
14
sub init_table {
15 15
  my ($self) = @_;
16

  
17 16
  $self->table($self->controller->profile->get('table') eq 'customer' ? 'customer' : 'vendor');
18
  $self->class('SL::DB::' . ucfirst($self->table));
17
}
19 18

  
20
  $self->SUPER::run;
19
sub init_class {
20
  my ($self) = @_;
21
  $self->class('SL::DB::' . ucfirst($self->table));
21 22
}
22 23

  
23 24
sub check_objects {
......
81 82
  $self->SUPER::save_objects(data => $without_number);
82 83
}
83 84

  
85
sub field_lengths {
86
  return ( name           => 75,
87
           department_1   => 75,
88
           department_2   => 75,
89
           street         => 75,
90
           zipcode        => 10,
91
           city           => 75,
92
           country        => 75,
93
           contact        => 75,
94
           phone          => 30,
95
           fax            => 30,
96
           account_number => 15,
97
           bank_code      => 10,
98
           language       => 5,
99
           username       => 50,
100
           ustid          => 14,
101
           iban           => 100,
102
           bic            => 100,
103
         );
104
}
105

  
84 106
1;

Auch abrufbar als: Unified diff