From aee10de25a63ec46afee4aec4b50ff509c0dcfd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 10 Jan 2013 16:34:56 +0100 Subject: [PATCH] Error Reporting, und robuster gegen Fehler im Report save/load --- SL/Controller/CsvImport.pm | 20 +++++++++++++++++-- SL/Controller/CsvImport/Part.pm | 2 +- .../csv_import/_deferred_results.html | 2 +- templates/webpages/csv_import/form.html | 10 ++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 0736d917b..bc0534f10 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -8,6 +8,7 @@ use SL::DB::CsvImportReport; use SL::DB::Unit; use SL::DB::Helper::Paginated (); use SL::Helper::Flash; +use SL::Locale::String; use SL::SessionFile; use SL::Controller::CsvImport::Contact; use SL::Controller::CsvImport::CustomerVendor; @@ -100,6 +101,15 @@ sub action_result { if ($data->{progress}{finished} || $data->{errors}) { $self->render('csv_import/_deferred_report', { no_layout => 1 }); } else { + if (!$self->task_server->is_running) { + $self->task_server->start; + $self->{status_text} = t8('Task Server is not running, starting it now. If this does not change, please check your task server config'); + } elsif (my $phase = $data->{progress}{phase}) { + $self->{status_text} = "$data->{progress}{plan}{$phase} / $data->{progress}{num_phases} " . t8($phase); + } else { + $self->{status_text} = t8('Import not started yet, please wait...'); + } + $self->render('csv_import/_deferred_results', { no_layout => 1 }); } } @@ -130,6 +140,10 @@ sub action_report { my $report_id = $params{report_id} || $::form->{id}; $self->{report} = SL::DB::Manager::CsvImportReport->find_by(id => $report_id); + + if (!$self->{report}) { + $::form->error(t8('No report with id #1', $report_id)); + } my $num_rows = $self->{report}->numrows; my $num_cols = SL::DB::Manager::CsvImportReportRow->get_all_count(query => [ csv_import_report_id => $report_id, row => 0 ]); @@ -384,7 +398,9 @@ sub save_report { type => $self->type, file => '', numrows => scalar @{ $self->data }, - )->save(cascade => 1); + ); + + $report->save(cascade => 1) or die $report->db->error; my $dbh = $::form->get_standard_dbh; $dbh->begin_work; @@ -421,7 +437,7 @@ sub save_report { my $o2 = $o1 + @methods; for my $row (0 .. $#{ $self->data }) { - $self->track_progress(progress => $row / @{ $self->data } * 100) if $row % 100 == 0; + $self->track_progress(progress => $row / @{ $self->data } * 100) if $row % 1000 == 0; my $data_row = $self->{data}[$row]; $sth->execute($report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods; diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index d7a892bdd..5529082ff 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -110,7 +110,7 @@ sub check_objects { my $i; my $num_data = scalar @{ $self->controller->data }; foreach my $entry (@{ $self->controller->data }) { - $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 1000 == 0; + $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0; $self->check_buchungsgruppe($entry); $self->check_type($entry); diff --git a/templates/webpages/csv_import/_deferred_results.html b/templates/webpages/csv_import/_deferred_results.html index 1a411f00e..7f68a32d5 100644 --- a/templates/webpages/csv_import/_deferred_results.html +++ b/templates/webpages/csv_import/_deferred_results.html @@ -24,7 +24,7 @@ } [%- UNLESS SELF.background_job.data_as_hash.errors %] $(document).ready(function(){ - $('#progress_description').html('[% SELF.background_job.data_as_hash.progress.plan.${SELF.background_job.data_as_hash.progress.phase} %] / [% SELF.background_job.data_as_hash.progress.num_phases %] [% SELF.background_job.data_as_hash.progress.phase | $T8 | html %]'); + $('#progress_description').html('[% SELF.status_text | html %]'); $('#progressbar').progressbar({ value: [% SELF.background_job.data_as_hash.progress.progress * 1 %] }); window.setTimeout(reload_results, 500); }) diff --git a/templates/webpages/csv_import/form.html b/templates/webpages/csv_import/form.html index 866584f53..8eaed1786 100644 --- a/templates/webpages/csv_import/form.html +++ b/templates/webpages/csv_import/form.html @@ -106,6 +106,13 @@

[%- LxERP.t8('Settings') %]

+ + + +
+ [% L.submit_tag('action_test', LxERP.t8('Test and preview')) %] [% L.submit_tag('action_import', LxERP.t8('Import'), style='display:none') %] -- 2.20.1