Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d7492165

Von Sven Schöling vor fast 12 Jahren hinzugefügt

  • ID d74921657d967900bded4aaf4805647e9cf83562
  • Vorgänger 93d4967b
  • Nachfolger 98f37c10

Weitere Verbesserungen am asynchronen Import.

- tracking
- profile/session handling

Unterschiede anzeigen:

SL/Controller/CsvImport.pm
24 24
(
25 25
 scalar                  => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen all_units
26 26
                                 import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns file) ],
27
 'scalar --get_set_init' => [ qw(worker) ]
27
 'scalar --get_set_init' => [ qw(worker) ],
28
 'array'                 => [
29
   progress_tracker     => { },
30
   add_progress_tracker => {  interface => 'add', hash_key => 'progress_tracker' },
31
 ],
28 32
);
29 33

  
30 34
__PACKAGE__->run_before('check_auth');
......
81 85

  
82 86
  my $data = $self->{background_job}->data_as_hash;
83 87

  
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
  }
88
  my $profile = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id});
89 89

  
90 90
  $self->profile($profile);
91 91

  
92 92
  if ($data->{progress} < 100) {
93 93
    $self->render('csv_import/_deferred_results', { no_layout => 1 });
94 94
  } else {
95
   die 'what? done? panic, no idea what to do';
95
    $self->action_report(report_id => $data->{report_id}, no_layout => 1);
96 96
  }
97 97
}
98 98

  
......
221 221
sub test_and_import {
222 222
  my ($self, %params) = @_;
223 223

  
224
  $self->profile_from_form;
225

  
226
  if ($::form->{file}) {
227
    my $file = SL::SessionFile->new($self->csv_file_name, mode => '>');
228
    $file->fh->print($::form->{file});
229
    $file->fh->close;
230
  }
231

  
232
  my $file = SL::SessionFile->new($self->csv_file_name, mode => '<', encoding => $self->profile->get('charset'));
233
  if (!$file->fh) {
234
    flash('error', $::locale->text('No file has been uploaded yet.'));
235
    return $self->action_new;
236
  }
224
  my $file = SL::SessionFile->new(
225
    $self->csv_file_name,
226
    mode       => '<',
227
    encoding   => $self->profile->get('charset'),
228
    session_id => $params{session_id}
229
  );
237 230

  
238 231
  $self->file($file);
239 232

  
......
244 237
  $self->num_imported(0);
245 238
  $worker->save_objects if !$params{test};
246 239

  
247
  $self->save_report;
248

  
249 240
  $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data || [] });
250 241
  $self->import_status($params{test} ? 'tested' : 'imported');
251 242

  
252
  flash('info', $::locale->text('Objects have been imported.')) if !$params{test};
243
#  flash('info', $::locale->text('Objects have been imported.')) if !$params{test};
253 244
}
254 245

  
255 246
sub load_default_profile {
......
401 392
  $self->worker->setup_displayable_columns;
402 393
}
403 394

  
395
sub track_progress {
396
  my ($self, $progress) = @_;
397

  
398
  for my $tracker ($self->progress_tracker) {
399
    $tracker->track_progress($progress);
400
  }
401
}
402

  
404 403

  
405 404
1;

Auch abrufbar als: Unified diff