X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/6f92326a8f2c1f9205a062d32ed8f1abdaa4b7b5..a60b31d79b1ec87fbb804d53a4bf09186eda8ea3:/SL/Controller/CsvImport/Base.pm diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index f84d54b0e..4de38edcf 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -22,6 +22,8 @@ use Rose::Object::MakeMethods::Generic sub run { my ($self) = @_; + $self->controller->track_progress(phase => 'parsing csv', progress => 0); + my $profile = $self->profile; $self->csv(SL::Helper::Csv->new(file => $self->file->file_name, encoding => $self->controller->profile->get('charset'), @@ -29,14 +31,19 @@ sub run { profile => $profile, ignore_unknown_columns => 1, strict_profile => 1, + case_insensitive_header => 1, map { ( $_ => $self->controller->profile->get($_) ) } qw(sep_char escape_char quote_char), )); + $self->controller->track_progress(progress => 10); + my $old_numberformat = $::myconfig{numberformat}; $::myconfig{numberformat} = $self->controller->profile->get('numberformat'); $self->csv->parse; + $self->controller->track_progress(progress => 50); + $self->controller->errors([ $self->csv->errors ]) if $self->csv->errors; return if ( !$self->csv->header || $self->csv->errors ); @@ -49,9 +56,17 @@ sub run { $self->controller->info_headers({ used => { }, headers => [ ] }); my @objects = $self->csv->get_objects; + + $self->controller->track_progress(progress => 70); + my @raw_data = @{ $self->csv->get_data }; + + $self->controller->track_progress(progress => 80); + $self->controller->data([ pairwise { { object => $a, raw_data => $b, errors => [], information => [], info_data => {} } } @objects, @raw_data ]); + $self->controller->track_progress(progress => 90); + $self->check_objects; if ( $self->controller->profile->get('duplicates', 'no_check') ne 'no_check' ) { $self->check_std_duplicates(); @@ -59,6 +74,8 @@ sub run { } $self->fix_field_lengths; + $self->controller->track_progress(progress => 100); + $::myconfig{numberformat} = $old_numberformat; } @@ -212,6 +229,12 @@ sub init_profile { $profile{$col} = $name; } + if ($self->can('all_cvar_configs')) { + for (@{ $self->all_cvar_configs }) { + $profile{ 'cvar_' . $_->name } = ''; + } + } + $self->profile(\%profile); } @@ -357,7 +380,16 @@ sub save_objects { my $data = $params{data} || $self->controller->data; - foreach my $entry (@{ $data }) { + 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; + foreach my $entry_index (0 .. $#$data) { + my $entry = $data->[$entry_index]; next if @{ $entry->{errors} }; my $object = $entry->{object_to_save} || $entry->{object}; @@ -367,7 +399,14 @@ sub save_objects { } else { $self->controller->num_imported($self->controller->num_imported + 1); } + } continue { + if ($entry_index % 100 == 0) { + $dbh->commit; + $self->controller->track_progress(progress => $entry_index/scalar(@$data) * 100); # scale from 45..95%; + $dbh->begin_work; + } } + $dbh->commit; } sub field_lengths {