X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport.pm;h=99f53c0bd8852b440e75662ebe8f80a08ea74701;hb=d2799b104f9541f9ef47445f07c3bfadca7b5b7e;hp=e603faa407023b7b25b55eabfc60769c9a65b73f;hpb=31b1b2c2a84f79d030033a3974957a94a11f752c;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index e603faa40..99f53c0bd 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -11,6 +11,7 @@ use SL::Controller::CsvImport::Contact; use SL::Controller::CsvImport::CustomerVendor; use SL::Controller::CsvImport::Part; use SL::Controller::CsvImport::Shipto; +use SL::Controller::CsvImport::Project; use List::MoreUtils qw(none); @@ -18,8 +19,9 @@ use parent qw(SL::Controller::Base); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen all_units - import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns) ], + scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen all_units + import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns file) ], + 'scalar --get_set_init' => [ qw(worker) ] ); __PACKAGE__->run_before('check_auth'); @@ -99,7 +101,7 @@ sub check_auth { sub check_type { my ($self) = @_; - die "Invalid CSV import type" if none { $_ eq $::form->{profile}->{type} } qw(parts customers_vendors addresses contacts); + die "Invalid CSV import type" if none { $_ eq $::form->{profile}->{type} } qw(parts customers_vendors addresses contacts projects); $self->type($::form->{profile}->{type}); } @@ -141,6 +143,7 @@ sub render_inputs { : $self->type eq 'addresses' ? $::locale->text('CSV import: shipping addresses') : $self->type eq 'contacts' ? $::locale->text('CSV import: contacts') : $self->type eq 'parts' ? $::locale->text('CSV import: parts and services') + : $self->type eq 'projects' ? $::locale->text('CSV import: projects') : die; if ($self->{type} eq 'parts') { @@ -170,7 +173,10 @@ sub test_and_import { return $self->action_new; } - my $worker = $self->create_worker($file); + $self->file($file); + + my $worker = $self->worker(); + $worker->run; $self->num_imported(0); @@ -251,20 +257,27 @@ sub csv_file_name { return "csv-import-" . $self->type . ".csv"; } -sub create_worker { - my ($self, $file) = @_; +sub init_worker { + my $self = shift; + + my @args = (controller => $self); + + if ( $self->file() ) { + push(@args, file => $self->file()); + } - return $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file) - : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new( controller => $self, file => $file) - : $self->{type} eq 'addresses' ? SL::Controller::CsvImport::Shipto->new( controller => $self, file => $file) - : $self->{type} eq 'parts' ? SL::Controller::CsvImport::Part->new( controller => $self, file => $file) + return $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(@args) + : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new(@args) + : $self->{type} eq 'addresses' ? SL::Controller::CsvImport::Shipto->new(@args) + : $self->{type} eq 'parts' ? SL::Controller::CsvImport::Part->new(@args) + : $self->{type} eq 'projects' ? SL::Controller::CsvImport::Project->new(@args) : die "Program logic error"; } sub setup_help { my ($self) = @_; - $self->create_worker->setup_displayable_columns; + $self->worker->setup_displayable_columns; }