Revision d7492165
Von Sven Schöling vor fast 12 Jahren hinzugefügt
SL/BackgroundJob/CsvImport.pm | ||
---|---|---|
5 | 5 |
use parent qw(SL::BackgroundJob::Base); |
6 | 6 |
|
7 | 7 |
use YAML (); |
8 |
use SL::Controller::CsvImport; |
|
8 | 9 |
use SL::DB::CsvImportProfile; |
9 | 10 |
use SL::SessionFile::Random; |
10 | 11 |
|
... | ... | |
15 | 16 |
$package =~ s/SL::BackgroundJob:://; |
16 | 17 |
|
17 | 18 |
my $profile = delete $params{profile} || SL::DB::CsvImportProfile->new; |
18 |
my $result = delete $params{result} || SL::SessionFile::Random->new; |
|
19 |
my $new_profile = $profile->clone_and_reset_deep; |
|
20 |
$new_profile->save; |
|
19 | 21 |
|
20 | 22 |
my %data = ( |
21 |
profile => { $profile->flatten }, |
|
22 |
result => $result->file_name, |
|
23 | 23 |
%params, |
24 |
profile_id => $new_profile->id, |
|
25 |
session_id => $::auth->get_session_id, |
|
24 | 26 |
); |
25 | 27 |
|
26 | 28 |
my $job = SL::DB::BackgroundJob->new( |
... | ... | |
34 | 36 |
} |
35 | 37 |
|
36 | 38 |
sub profile { |
37 |
my ($self, $db_obj) = @_;
|
|
39 |
my ($self) = @_; |
|
38 | 40 |
|
39 | 41 |
if (!$self->{profile}) { |
40 |
$self->{profile} = SL::DB::CsvImportProfile->new; |
|
41 |
my $data = YAML::Load($db_obj->data); |
|
42 |
for (keys %$data) { |
|
43 |
$self->{profile}->set($_ => $data->{$_}); |
|
44 |
} |
|
42 |
my $data = YAML::Load($self->{db_obj}->data); |
|
43 |
$self->{profile} = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id}); |
|
45 | 44 |
} |
46 | 45 |
|
47 | 46 |
return $self->{profile}; |
... | ... | |
60 | 59 |
my ($self) = @_; |
61 | 60 |
|
62 | 61 |
my $c = SL::Controller::CsvImport->new; |
63 |
$c->profile($self->{profile}); |
|
64 |
$c->test_and_import(test => $self->); |
|
65 | 62 |
|
63 |
$c->profile($self->profile); |
|
64 |
$c->type($self->{db_obj}->data_as_hash->{type}); |
|
65 |
$c->add_progress_tracker($self); |
|
66 |
|
|
67 |
$c->test_and_import(test => 1, session_id => $self->{db_obj}->data_as_hash->{session_id}); |
|
68 |
|
|
69 |
my $report_id = $c->save_report; |
|
70 |
$self->{db_obj}->set_data(report_id => $report_id); |
|
71 |
$self->{db_obj}->save; |
|
72 |
|
|
73 |
$c->track_progress(100); |
|
74 |
} |
|
75 |
|
|
76 |
sub track_progress { |
|
77 |
my ($self, $progress) = @_; |
|
66 | 78 |
|
79 |
$self->{db_obj}->set_data(progress => $progress); |
|
80 |
$self->{db_obj}->save; |
|
67 | 81 |
} |
68 | 82 |
|
69 | 83 |
sub cleanup { |
Auch abrufbar als: Unified diff
Weitere Verbesserungen am asynchronen Import.
- tracking
- profile/session handling