Revision 82c3b7eb
Von Sven Schöling vor fast 12 Jahren hinzugefügt
SL/Controller/CsvImport.pm | ||
---|---|---|
13 | 13 |
use SL::Controller::CsvImport::Part; |
14 | 14 |
use SL::Controller::CsvImport::Shipto; |
15 | 15 |
use SL::Controller::CsvImport::Project; |
16 |
use SL::BackgroundJob::CsvImport; |
|
17 |
use SL::System::TaskServer; |
|
16 | 18 |
|
17 | 19 |
use List::MoreUtils qw(none); |
18 | 20 |
|
... | ... | |
43 | 45 |
|
44 | 46 |
sub action_test { |
45 | 47 |
my ($self) = @_; |
46 |
$self->test_and_import(test => 1); |
|
48 |
$self->test_and_import_deferred(test => 1);
|
|
47 | 49 |
} |
48 | 50 |
|
49 | 51 |
sub action_import { |
50 | 52 |
my $self = shift; |
51 |
$self->test_and_import(test => 0); |
|
53 |
$self->test_and_import_deferred(test => 0);
|
|
52 | 54 |
} |
53 | 55 |
|
54 | 56 |
sub action_save { |
... | ... | |
71 | 73 |
$self->redirect_to(action => 'new', 'profile.type' => $self->type); |
72 | 74 |
} |
73 | 75 |
|
76 |
sub action_result { |
|
77 |
my $self = shift; |
|
78 |
|
|
79 |
# load resultobject |
|
80 |
$self->{background_job} = SL::DB::Manager::BackgroundJob->find_by(id => $::form->{job}); |
|
81 |
|
|
82 |
my $data = $self->{background_job}->data_as_hash; |
|
83 |
|
|
84 |
my $profile = SL::DB::CsvImportProfile->new(type => $data->{type}); |
|
85 |
my $profile_data = $data->{profile}; |
|
86 |
for (keys %$profile_data) { |
|
87 |
$profile->set($_ => $profile_data->{$_}); |
|
88 |
} |
|
89 |
|
|
90 |
$self->profile($profile); |
|
91 |
|
|
92 |
if ($data->{progress} < 100) { |
|
93 |
$self->render('csv_import/_deferred_results', { no_layout => 1 }); |
|
94 |
} else { |
|
95 |
die 'what? done? panic, no idea what to do'; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
74 | 99 |
sub action_download_sample { |
75 | 100 |
my $self = shift; |
76 | 101 |
|
... | ... | |
157 | 182 |
$self->render('csv_import/form', title => $title); |
158 | 183 |
} |
159 | 184 |
|
185 |
sub test_and_import_deferred { |
|
186 |
my ($self, %params) = @_; |
|
187 |
|
|
188 |
$self->profile_from_form; |
|
189 |
|
|
190 |
if ($::form->{file}) { |
|
191 |
my $file = SL::SessionFile->new($self->csv_file_name, mode => '>'); |
|
192 |
$file->fh->print($::form->{file}); |
|
193 |
$file->fh->close; |
|
194 |
} |
|
195 |
|
|
196 |
$self->{background_job} = SL::BackgroundJob::CsvImport->create_job( |
|
197 |
file => $self->csv_file_name, |
|
198 |
profile => $self->profile, |
|
199 |
type => $self->profile->type, |
|
200 |
)->save; |
|
201 |
|
|
202 |
SL::System::TaskServer->start_if_not_running; |
|
203 |
SL::System::TaskServer->wake_up; |
|
204 |
|
|
205 |
flash('info', $::locale->text('Your import is beig processed.')); |
|
206 |
|
|
207 |
$self->{deferred} = 1; |
|
208 |
|
|
209 |
$self->render_inputs; |
|
210 |
} |
|
211 |
|
|
160 | 212 |
sub test_and_import { |
161 | 213 |
my ($self, %params) = @_; |
162 | 214 |
|
... | ... | |
189 | 241 |
$self->import_status($params{test} ? 'tested' : 'imported'); |
190 | 242 |
|
191 | 243 |
flash('info', $::locale->text('Objects have been imported.')) if !$params{test}; |
192 |
|
|
193 |
$self->action_new; |
|
194 | 244 |
} |
195 | 245 |
|
196 | 246 |
sub load_default_profile { |
Auch abrufbar als: Unified diff
Asynchroner Import