1 package SL::BackgroundJob::CsvImport;
 
   5 use parent qw(SL::BackgroundJob::Base);
 
   8 use SL::DB::CsvImportProfile;
 
   9 use SL::SessionFile::Random;
 
  12   my ($self_or_class, %params) = @_;
 
  14   my $package       = ref($self_or_class) || $self_or_class;
 
  15   $package          =~ s/SL::BackgroundJob:://;
 
  17   my $profile = delete $params{profile} || SL::DB::CsvImportProfile->new;
 
  18   my $new_profile = $profile->clone_and_reset_deep;
 
  23     profile_id => $new_profile->id,
 
  24     session_id => $::auth->get_session_id,
 
  27   my $job = SL::DB::BackgroundJob->new(
 
  30     package_name => $package,
 
  31     data         => YAML::Dump(\%data),
 
  40   if (!$self->{profile}) {
 
  41     my $data = YAML::Load($self->{db_obj}->data);
 
  42     $self->{profile} = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id});
 
  45   return $self->{profile};
 
  50   $self->{db_obj} = shift;
 
  58   require SL::Controller::CsvImport;
 
  59   my $c = SL::Controller::CsvImport->new;
 
  60   my $job = $self->{db_obj};
 
  62   $c->profile($self->profile);
 
  63   $c->type($job->data_as_hash->{type});
 
  64   $c->{employee_id} = $job->data_as_hash->{employee_id};
 
  66   my $test = $job->data_as_hash->{test};
 
  69   # $::locale->text('parsing csv')
 
  70   # $::locale->text('building data')
 
  71   # $::locale->text('saving data')
 
  72   # $::locale->text('building report')
 
  73   $self->track_progress(
 
  78     ( 'saving data'     => 3, )x!$test,
 
  79       'building report' => ($test ? 3 : 4),
 
  81     num_phases => ($test ? 3 : 4),
 
  83   $c->add_progress_tracker($self);
 
  86   $c->test_and_import(test => $test, session_id => $job->data_as_hash->{session_id});
 
  94     my $report_id = $c->save_report;
 
  95     $job->set_data(report_id => $report_id)->save;
 
  97     $c->track_progress(finished => 1);
 
 102   my ($self, %params) = @_;
 
 104   my $data = $self->{db_obj}->data_as_hash;
 
 105   my $progress = $data->{progress} || {};
 
 107   $progress->{$_} = $params{$_} for keys %params;
 
 108   $self->{db_obj}->set_data(progress => $progress);
 
 109   $self->{db_obj}->save;
 
 120 SL::Background::CsvImport - backend for automatic imports of csv data
 
 125 use SL::BackgroundJob::CsvImport;
 
 128 From a controller or external source:
 
 130   my $job = SL::BackgroundJob::CsvImport->create_job(
 
 143 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>