1 package SL::BackgroundJob::CsvImport;
5 use parent qw(SL::BackgroundJob::Base);
8 use SL::Controller::CsvImport;
9 use SL::DB::CsvImportProfile;
10 use SL::SessionFile::Random;
13 my ($self_or_class, %params) = @_;
15 my $package = ref($self_or_class) || $self_or_class;
16 $package =~ s/SL::BackgroundJob:://;
18 my $profile = delete $params{profile} || SL::DB::CsvImportProfile->new;
19 my $new_profile = $profile->clone_and_reset_deep;
24 profile_id => $new_profile->id,
25 session_id => $::auth->get_session_id,
28 my $job = SL::DB::BackgroundJob->new(
31 package_name => $package,
32 data => YAML::Dump(\%data),
41 if (!$self->{profile}) {
42 my $data = YAML::Load($self->{db_obj}->data);
43 $self->{profile} = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id});
46 return $self->{profile};
51 $self->{db_obj} = shift;
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});
65 my $test = $job->data_as_hash->{test};
68 # $::locale->text('parsing csv')
69 # $::locale->text('building data')
70 # $::locale->text('saving data')
71 # $::locale->text('building report')
72 $self->track_progress(
77 ( 'saving data' => 3, )x!$test,
78 'building report' => ($test ? 3 : 4),
80 num_phases => ($test ? 3 : 4),
82 $c->add_progress_tracker($self);
85 $c->test_and_import(test => $test, session_id => $job->data_as_hash->{session_id});
93 my $report_id = $c->save_report;
94 $job->set_data(report_id => $report_id)->save;
96 $c->track_progress(finished => 1);
101 my ($self, %params) = @_;
103 my $data = $self->{db_obj}->data_as_hash;
104 my $progress = $data->{progress} || {};
106 $progress->{$_} = $params{$_} for keys %params;
107 $self->{db_obj}->set_data(progress => $progress);
108 $self->{db_obj}->save;
119 SL::Background::CsvImport - backend for automatic imports of csv data
124 use SL::BackgroundJob::CsvImport;
127 From a controller or external source:
129 my $job = SL::BackgroundJob::CsvImport->create_job(
142 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>