Revision 98f37c10
Von Sven Schöling vor fast 12 Jahren hinzugefügt
SL/BackgroundJob/CsvImport.pm | ||
---|---|---|
59 | 59 |
my ($self) = @_; |
60 | 60 |
|
61 | 61 |
my $c = SL::Controller::CsvImport->new; |
62 |
my $job = $self->{db_obj}; |
|
62 | 63 |
|
63 | 64 |
$c->profile($self->profile); |
64 |
$c->type($self->{db_obj}->data_as_hash->{type}); |
|
65 |
$c->type($job->data_as_hash->{type}); |
|
66 |
|
|
67 |
my $test = $job->data_as_hash->{test}; |
|
68 |
|
|
69 |
$self->track_progress( |
|
70 |
progress => 0, |
|
71 |
plan => { |
|
72 |
'parsing csv' => 1, |
|
73 |
'building data' => 2, |
|
74 |
( 'saving data' => 3, )x!!$test, |
|
75 |
'building report' => ($test ? 3 : 4), |
|
76 |
}, |
|
77 |
num_phases => ($test ? 3 : 4), |
|
78 |
); |
|
65 | 79 |
$c->add_progress_tracker($self); |
66 | 80 |
|
67 |
$c->test_and_import(test => 1, session_id => $self->{db_obj}->data_as_hash->{session_id}); |
|
68 | 81 |
|
69 |
my $report_id = $c->save_report; |
|
70 |
$self->{db_obj}->set_data(report_id => $report_id); |
|
71 |
$self->{db_obj}->save; |
|
82 |
$c->test_and_import(test => 1, session_id => $job->data_as_hash->{session_id}); |
|
83 |
|
|
84 |
if ($c->errors) { |
|
85 |
$job->set_data( |
|
86 |
errors => $c->errors, |
|
87 |
progress => -1, |
|
88 |
)->save; |
|
89 |
} else { |
|
72 | 90 |
|
73 |
$c->track_progress(100); |
|
91 |
my $report_id = $c->save_report; |
|
92 |
$job->set_data(report_id => $report_id)->save; |
|
93 |
|
|
94 |
$c->track_progress(finished => 1); |
|
95 |
} |
|
74 | 96 |
} |
75 | 97 |
|
76 | 98 |
sub track_progress { |
77 |
my ($self, $progress) = @_; |
|
99 |
my ($self, %params) = @_; |
|
100 |
|
|
101 |
my $data = $self->{db_obj}->data_as_hash; |
|
102 |
my $progress = $data->{progress} || {}; |
|
78 | 103 |
|
104 |
$progress->{$_} = $params{$_} for keys %params; |
|
79 | 105 |
$self->{db_obj}->set_data(progress => $progress); |
80 | 106 |
$self->{db_obj}->save; |
81 | 107 |
} |
Auch abrufbar als: Unified diff
Progress genauer anzeigen