projects
/
kivitendo-erp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d749216
)
Progress genauer anzeigen
author
Sven Schöling
<s.schoeling@linet-services.de>
Thu, 15 Nov 2012 16:17:20 +0000
(17:17 +0100)
committer
Sven Schöling
<s.schoeling@linet-services.de>
Fri, 11 Jan 2013 12:57:17 +0000
(13:57 +0100)
SL/BackgroundJob/CsvImport.pm
patch
|
blob
|
history
SL/Controller/CsvImport.pm
patch
|
blob
|
history
SL/Controller/CsvImport/Base.pm
patch
|
blob
|
history
SL/Controller/CsvImport/Part.pm
patch
|
blob
|
history
SL/DB/BackgroundJob.pm
patch
|
blob
|
history
templates/webpages/csv_import/_deferred_results.html
patch
|
blob
|
history
diff --git
a/SL/BackgroundJob/CsvImport.pm
b/SL/BackgroundJob/CsvImport.pm
index
60147f8
..
66d830f
100644
(file)
--- a/
SL/BackgroundJob/CsvImport.pm
+++ b/
SL/BackgroundJob/CsvImport.pm
@@
-59,23
+59,49
@@
sub do_import {
my ($self) = @_;
my $c = SL::Controller::CsvImport->new;
my ($self) = @_;
my $c = SL::Controller::CsvImport->new;
+ my $job = $self->{db_obj};
$c->profile($self->profile);
$c->profile($self->profile);
- $c->type($self->{db_obj}->data_as_hash->{type});
+ $c->type($job->data_as_hash->{type});
+
+ my $test = $job->data_as_hash->{test};
+
+ $self->track_progress(
+ progress => 0,
+ plan => {
+ 'parsing csv' => 1,
+ 'building data' => 2,
+ ( 'saving data' => 3, )x!!$test,
+ 'building report' => ($test ? 3 : 4),
+ },
+ num_phases => ($test ? 3 : 4),
+ );
$c->add_progress_tracker($self);
$c->add_progress_tracker($self);
- $c->test_and_import(test => 1, session_id => $self->{db_obj}->data_as_hash->{session_id});
- my $report_id = $c->save_report;
- $self->{db_obj}->set_data(report_id => $report_id);
- $self->{db_obj}->save;
+ $c->test_and_import(test => 1, session_id => $job->data_as_hash->{session_id});
+
+ if ($c->errors) {
+ $job->set_data(
+ errors => $c->errors,
+ progress => -1,
+ )->save;
+ } else {
- $c->track_progress(100);
+ my $report_id = $c->save_report;
+ $job->set_data(report_id => $report_id)->save;
+
+ $c->track_progress(finished => 1);
+ }
}
sub track_progress {
}
sub track_progress {
- my ($self, $progress) = @_;
+ my ($self, %params) = @_;
+
+ my $data = $self->{db_obj}->data_as_hash;
+ my $progress = $data->{progress} || {};
+ $progress->{$_} = $params{$_} for keys %params;
$self->{db_obj}->set_data(progress => $progress);
$self->{db_obj}->save;
}
$self->{db_obj}->set_data(progress => $progress);
$self->{db_obj}->save;
}
diff --git
a/SL/Controller/CsvImport.pm
b/SL/Controller/CsvImport.pm
index
4db025e
..
29947a1
100644
(file)
--- a/
SL/Controller/CsvImport.pm
+++ b/
SL/Controller/CsvImport.pm
@@
-89,7
+89,11
@@
sub action_result {
$self->profile($profile);
$self->profile($profile);
- if ($data->{progress} < 100) {
+ if ($data->{errors} and my $first_error = $data->{errors}->[0]) {
+ flash('error', $::locale->text('There was an error parsing the csv file: #1 in line #2.', $first_error->[2], $first_error->[0]));
+ }
+
+ if (!$data->{progress}{finished}) {
$self->render('csv_import/_deferred_results', { no_layout => 1 });
} else {
$self->action_report(report_id => $data->{report_id}, no_layout => 1);
$self->render('csv_import/_deferred_results', { no_layout => 1 });
} else {
$self->action_report(report_id => $data->{report_id}, no_layout => 1);
@@
-206,6
+210,7
@@
sub test_and_import_deferred {
file => $self->csv_file_name,
profile => $self->profile,
type => $self->profile->type,
file => $self->csv_file_name,
profile => $self->profile,
type => $self->profile->type,
+ test => $params{test},
)->save;
SL::System::TaskServer->start_if_not_running;
)->save;
SL::System::TaskServer->start_if_not_running;
@@
-234,6
+239,8
@@
sub test_and_import {
$worker->run;
$worker->run;
+ return if $self->errors;
+
$self->num_imported(0);
$worker->save_objects if !$params{test};
$self->num_imported(0);
$worker->save_objects if !$params{test};
@@
-313,6
+320,8
@@
sub char_map {
sub save_report {
my ($self, $report_id) = @_;
sub save_report {
my ($self, $report_id) = @_;
+ $self->track_progress(phase => 'building report', progress => 0);
+
my $clone_profile = $self->profile->clone_and_reset_deep;
$clone_profile->save; # weird bug. if this isn't saved before adding it to the report, it will default back to the last profile.
my $clone_profile = $self->profile->clone_and_reset_deep;
$clone_profile->save; # weird bug. if this isn't saved before adding it to the report, it will default back to the last profile.
@@
-349,6
+358,7
@@
sub save_report {
my $o2 = $o1 + @methods;
for my $row (0 .. $#{ $self->data }) {
my $o2 = $o1 + @methods;
for my $row (0 .. $#{ $self->data }) {
+ $self->track_progress(progress => $row / @{ $self->data } * 100) if $row % 100 == 0;
my $data_row = $self->{data}[$row];
$sth->execute($report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods;
my $data_row = $self->{data}[$row];
$sth->execute($report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods;
@@
-393,10
+403,10
@@
sub setup_help {
}
sub track_progress {
}
sub track_progress {
- my ($self,
$progres
s) = @_;
+ my ($self,
%param
s) = @_;
for my $tracker ($self->progress_tracker) {
for my $tracker ($self->progress_tracker) {
- $tracker->track_progress(
$progres
s);
+ $tracker->track_progress(
%param
s);
}
}
}
}
diff --git
a/SL/Controller/CsvImport/Base.pm
b/SL/Controller/CsvImport/Base.pm
index
67ca191
..
4de38ed
100644
(file)
--- a/
SL/Controller/CsvImport/Base.pm
+++ b/
SL/Controller/CsvImport/Base.pm
@@
-22,7
+22,7
@@
use Rose::Object::MakeMethods::Generic
sub run {
my ($self) = @_;
sub run {
my ($self) = @_;
- $self->controller->track_progress(0);
+ $self->controller->track_progress(
phase => 'parsing csv', progress =>
0);
my $profile = $self->profile;
$self->csv(SL::Helper::Csv->new(file => $self->file->file_name,
my $profile = $self->profile;
$self->csv(SL::Helper::Csv->new(file => $self->file->file_name,
@@
-35,14
+35,14
@@
sub run {
map { ( $_ => $self->controller->profile->get($_) ) } qw(sep_char escape_char quote_char),
));
map { ( $_ => $self->controller->profile->get($_) ) } qw(sep_char escape_char quote_char),
));
- $self->controller->track_progress(
1
);
+ $self->controller->track_progress(
progress => 10
);
my $old_numberformat = $::myconfig{numberformat};
$::myconfig{numberformat} = $self->controller->profile->get('numberformat');
$self->csv->parse;
my $old_numberformat = $::myconfig{numberformat};
$::myconfig{numberformat} = $self->controller->profile->get('numberformat');
$self->csv->parse;
- $self->controller->track_progress(
3
);
+ $self->controller->track_progress(
progress => 50
);
$self->controller->errors([ $self->csv->errors ]) if $self->csv->errors;
$self->controller->errors([ $self->csv->errors ]) if $self->csv->errors;
@@
-55,21
+55,17
@@
sub run {
$self->controller->raw_data_headers({ used => { }, headers => [ ] });
$self->controller->info_headers({ used => { }, headers => [ ] });
$self->controller->raw_data_headers({ used => { }, headers => [ ] });
$self->controller->info_headers({ used => { }, headers => [ ] });
- $::lxdebug->dump(0, "self", $self->controller->info_headers);
- $::lxdebug->dump(0, "self", $self->controller->headers);
- $::lxdebug->dump(0, "self", $self->controller->raw_data_headers);
-
my @objects = $self->csv->get_objects;
my @objects = $self->csv->get_objects;
- $self->controller->track_progress(
4
);
+ $self->controller->track_progress(
progress => 70
);
my @raw_data = @{ $self->csv->get_data };
my @raw_data = @{ $self->csv->get_data };
- $self->controller->track_progress(
4.5
);
+ $self->controller->track_progress(
progress => 80
);
$self->controller->data([ pairwise { { object => $a, raw_data => $b, errors => [], information => [], info_data => {} } } @objects, @raw_data ]);
$self->controller->data([ pairwise { { object => $a, raw_data => $b, errors => [], information => [], info_data => {} } } @objects, @raw_data ]);
- $self->controller->track_progress(
5
);
+ $self->controller->track_progress(
progress => 90
);
$self->check_objects;
if ( $self->controller->profile->get('duplicates', 'no_check') ne 'no_check' ) {
$self->check_objects;
if ( $self->controller->profile->get('duplicates', 'no_check') ne 'no_check' ) {
@@
-78,7
+74,7
@@
sub run {
}
$self->fix_field_lengths;
}
$self->fix_field_lengths;
- $self->controller->track_progress(
99
);
+ $self->controller->track_progress(
progress => 100
);
$::myconfig{numberformat} = $old_numberformat;
}
$::myconfig{numberformat} = $old_numberformat;
}
@@
-387,6
+383,8
@@
sub save_objects {
return unless $data->[0];
return unless $data->[0]{object};
return unless $data->[0];
return unless $data->[0]{object};
+ $self->controller->track_progress(phase => 'saving objects', progress => 0); # scale from 45..95%;
+
my $dbh = $data->[0]{object}->db;
$dbh->begin_work;
my $dbh = $data->[0]{object}->db;
$dbh->begin_work;
@@
-404,7
+402,7
@@
sub save_objects {
} continue {
if ($entry_index % 100 == 0) {
$dbh->commit;
} continue {
if ($entry_index % 100 == 0) {
$dbh->commit;
- $self->controller->track_progress(
45 + $entry_index/scalar(@$data) * 5
0); # scale from 45..95%;
+ $self->controller->track_progress(
progress => $entry_index/scalar(@$data) * 10
0); # scale from 45..95%;
$dbh->begin_work;
}
}
$dbh->begin_work;
}
}
diff --git
a/SL/Controller/CsvImport/Part.pm
b/SL/Controller/CsvImport/Part.pm
index
36dccc6
..
30c3719
100644
(file)
--- a/
SL/Controller/CsvImport/Part.pm
+++ b/
SL/Controller/CsvImport/Part.pm
@@
-103,12
+103,14
@@
sub check_objects {
return unless @{ $self->controller->data };
return unless @{ $self->controller->data };
+ $self->controller->track_progress(phase => 'building data', progress => 0);
+
$self->makemodel_columns({});
my $i;
my $num_data = scalar @{ $self->controller->data };
foreach my $entry (@{ $self->controller->data }) {
$self->makemodel_columns({});
my $i;
my $num_data = scalar @{ $self->controller->data };
foreach my $entry (@{ $self->controller->data }) {
- $self->controller->track_progress(
8 + ($i/$num_data * 40)) if $i % 100 == 0; # scale from 5..45%
+ $self->controller->track_progress(
progress => $i/$num_data * 100) if $i % 100 == 0;
$self->check_buchungsgruppe($entry);
$self->check_type($entry);
$self->check_buchungsgruppe($entry);
$self->check_type($entry);
diff --git
a/SL/DB/BackgroundJob.pm
b/SL/DB/BackgroundJob.pm
index
1a9c869
..
c838685
100644
(file)
--- a/
SL/DB/BackgroundJob.pm
+++ b/
SL/DB/BackgroundJob.pm
@@
-83,6
+83,8
@@
sub set_data {
my $data = YAML::Load($self->data);
$data->{$_} = $data{$_} for keys %data;
$self->data(YAML::Dump($data));
my $data = YAML::Load($self->data);
$data->{$_} = $data{$_} for keys %data;
$self->data(YAML::Dump($data));
+
+ $self;
}
sub validate {
}
sub validate {
diff --git
a/templates/webpages/csv_import/_deferred_results.html
b/templates/webpages/csv_import/_deferred_results.html
index
f4267b3
..
bc6d683
100644
(file)
--- a/
templates/webpages/csv_import/_deferred_results.html
+++ b/
templates/webpages/csv_import/_deferred_results.html
@@
-1,5
+1,12
@@
+[%- USE L %]
+[%- USE T8 %]
+[%- USE HTML %]
+
+<h2>[% 'Import Status' | $T8 %]</h2>
+
+[% PROCESS 'common/flash.html' %]
+<div id='progress_description'></div>
<div id='progressbar'></div>
<div id='progressbar'></div>
-[% IF progress < 100 %]
<script type='text/javascript'>
function reload_results () {
$.ajax({
<script type='text/javascript'>
function reload_results () {
$.ajax({
@@
-13,9
+20,11
@@
error: function(e) { alert(e) },
});
}
error: function(e) { alert(e) },
});
}
+[%- UNLESS SELF.background_job.data_as_hash.progress < 0 %]
$(document).ready(function(){
$(document).ready(function(){
- $('#progressbar').progressbar({ value: [% SELF.background_job.data_as_hash.progress * 1 %] });
+ $('#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 %]');
+ $('#progressbar').progressbar({ value: [% SELF.background_job.data_as_hash.progress.progress * 1 %] });
window.setTimeout(reload_results, 100);
})
window.setTimeout(reload_results, 100);
})
+[%- END %]
</script>
</script>
-[% END %]