epic-ts
[kivitendo-erp.git] / SL / BackgroundJob / CsvImport.pm
index 98aed9c..b5e6f29 100644 (file)
@@ -5,7 +5,6 @@ use strict;
 use parent qw(SL::BackgroundJob::Base);
 
 use YAML ();
-use SL::Controller::CsvImport;
 use SL::DB::CsvImportProfile;
 use SL::SessionFile::Random;
 
@@ -51,18 +50,18 @@ sub run {
   $self->{db_obj} = shift;
 
   $self->do_import;
-
-  $self->cleanup;
 }
 
 sub do_import {
   my ($self) = @_;
 
+  require SL::Controller::CsvImport;
   my $c = SL::Controller::CsvImport->new;
   my $job = $self->{db_obj};
 
   $c->profile($self->profile);
   $c->type($job->data_as_hash->{type});
+  $c->{employee_id} = $job->data_as_hash->{employee_id};
 
   my $test = $job->data_as_hash->{test};
 
@@ -76,15 +75,16 @@ sub do_import {
     plan => {
       'parsing csv'     => 1,
       'building data'   => 2,
-    ( 'saving data'     => 3, )x!!$test,
+    ( 'saving data'     => 3, )x!$test,
       'building report' => ($test ? 3 : 4),
     },
     num_phases => ($test ? 3 : 4),
   );
   $c->add_progress_tracker($self);
 
+  my $session_id = $job->data_as_hash->{session_id};
 
-  $c->test_and_import(test => 1, session_id => $job->data_as_hash->{session_id});
+  $c->test_and_import(test => $test, session_id => $session_id);
 
   if ($c->errors) {
     $job->set_data(
@@ -92,7 +92,7 @@ sub do_import {
     )->save;
   } else {
 
-    my $report_id = $c->save_report;
+    my $report_id = $c->save_report(session_id => $session_id);
     $job->set_data(report_id => $report_id)->save;
 
     $c->track_progress(finished => 1);
@@ -110,10 +110,6 @@ sub track_progress {
   $self->{db_obj}->save;
 }
 
-sub cleanup {
-
-}
-
 1;
 
 __END__