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;
63 $c->profile($self->profile);
64 $c->type($self->{db_obj}->data_as_hash->{type});
65 $c->add_progress_tracker($self);
67 $c->test_and_import(test => 1, session_id => $self->{db_obj}->data_as_hash->{session_id});
69 my $report_id = $c->save_report;
70 $self->{db_obj}->set_data(report_id => $report_id);
71 $self->{db_obj}->save;
73 $c->track_progress(100);
77 my ($self, $progress) = @_;
79 $self->{db_obj}->set_data(progress => $progress);
80 $self->{db_obj}->save;
95 SL::Background::CsvImport - backend for automatic imports of csv data
100 use SL::BackgroundJob::CsvImport;
103 From a controller or external source:
105 my $job = SL::BackgroundJob::CsvImport->create_job(
118 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>