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;
61 my $c = SL::Controller::CsvImport->new;
62 my $job = $self->{db_obj};
64 $c->profile($self->profile);
65 $c->type($job->data_as_hash->{type});
67 my $test = $job->data_as_hash->{test};
69 $self->track_progress(
74 ( 'saving data' => 3, )x!!$test,
75 'building report' => ($test ? 3 : 4),
77 num_phases => ($test ? 3 : 4),
79 $c->add_progress_tracker($self);
82 $c->test_and_import(test => 1, session_id => $job->data_as_hash->{session_id});
91 my $report_id = $c->save_report;
92 $job->set_data(report_id => $report_id)->save;
94 $c->track_progress(finished => 1);
99 my ($self, %params) = @_;
101 my $data = $self->{db_obj}->data_as_hash;
102 my $progress = $data->{progress} || {};
104 $progress->{$_} = $params{$_} for keys %params;
105 $self->{db_obj}->set_data(progress => $progress);
106 $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>