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);
85 my $session_id = $job->data_as_hash->{session_id};
87 $c->test_and_import(test => $test, session_id => $session_id);
95 my $report_id = $c->save_report(session_id => $session_id);
96 $job->set_data(report_id => $report_id)->save;
98 $c->track_progress(finished => 1);
103 my ($self, %params) = @_;
105 my $data = $self->{db_obj}->data_as_hash;
106 my $progress = $data->{progress} || {};
108 $progress->{$_} = $params{$_} for keys %params;
109 $self->{db_obj}->set_data(progress => $progress);
110 $self->{db_obj}->save;
121 SL::Background::CsvImport - backend for automatic imports of csv data
126 use SL::BackgroundJob::CsvImport;
129 From a controller or external source:
131 my $job = SL::BackgroundJob::CsvImport->create_job(
144 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>