X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/6261d6ca23a2943f691d45ae6944da1a37eb7867..31b247eeafbde0d9c043768489bf1228bd997d60:/SL/Controller/CsvImport.pm diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 3c925abdd..43d6fbf7a 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -8,6 +8,7 @@ use SL::DB::CsvImportProfile; use SL::DB::CsvImportReport; use SL::DB::Unit; use SL::DB::Helper::Paginated (); +use SL::DBUtils qw(do_statement); use SL::Helper::Flash; use SL::Locale::String; use SL::SessionFile; @@ -32,7 +33,6 @@ use parent qw(SL::Controller::Base); use Rose::Object::MakeMethods::Generic ( 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 - csv_import_access import_status errors headers raw_data_headers info_headers data num_importable displayable_columns file all_taxzones) ], 'scalar --get_set_init' => [ qw(worker task_server num_imported mappings) ], 'array' => [ @@ -41,7 +41,7 @@ use Rose::Object::MakeMethods::Generic ], ); -__PACKAGE__->run_before('check_auth'); +__PACKAGE__->run_before('check_auth', except => [ qw(report) ]); __PACKAGE__->run_before('ensure_form_structure'); __PACKAGE__->run_before('check_type', except => [ qw(report) ]); __PACKAGE__->run_before('load_all_profiles'); @@ -163,7 +163,6 @@ sub action_report { } 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 ]); # manual paginating, yuck my $page = $::form->{page} || 1; @@ -267,13 +266,8 @@ sub action_add_mapping_from_upload { # sub check_auth { - my ($self) = @_; - if ( $::form->{csv_import_access} ) { - $self->csv_import_access($::form->{csv_import_access}); - return $::auth->assert($self->csv_import_access); - } else { - return $::auth->assert('config'); - } + $_[0]->check_type; + $_[0]->worker->check_auth; } sub check_type { @@ -339,6 +333,8 @@ sub render_inputs { $self->setup_help; + $self->setup_render_inputs_action_bar; + $self->render('csv_import/form', title => $title); } @@ -550,7 +546,7 @@ sub save_report_single { push @raw_methods, $self->raw_data_headers->{headers}->[$i]; } - $sth->execute($report->id, $_, 0, $headers[$_]) for 0 .. $#headers; + do_statement($::form, $sth, $query, $report->id, $_, 0, $headers[$_]) for 0 .. $#headers; # col offsets my $o1 = @info_methods; @@ -560,12 +556,12 @@ sub save_report_single { $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; - $sth->execute($report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] }) for 0 .. $#methods; - $sth->execute($report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] }) for 0 .. $#raw_methods; + do_statement($::form, $sth, $query, $report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods; + do_statement($::form, $sth, $query, $report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] }) for 0 .. $#methods; + do_statement($::form, $sth, $query, $report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] }) for 0 .. $#raw_methods; - $sth2->execute($report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] }; - $sth2->execute($report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] }; } 1; }) or do { die SL::DB->client->error }; @@ -629,7 +625,7 @@ sub save_report_multi { for my $i (0 .. $#{ $self->worker->profile }) { my $row_ident = $self->worker->profile->[$i]->{row_ident}; - $sth->execute($report->id, $_, $i, $headers->{$row_ident}->[$_]) for 0 .. $#{ $headers->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $_, $i, $headers->{$row_ident}->[$_]) for 0 .. $#{ $headers->{$row_ident} }; } # col offsets @@ -653,12 +649,12 @@ sub save_report_multi { my $o1 = $off1->{$row_ident}; my $o2 = $off2->{$row_ident}; - $sth->execute($report->id, $_, $row + $n_header_rows, $data_row->{info_data}{ $info_methods->{$row_ident}->[$_] }) for 0 .. $#{ $info_methods->{$row_ident} }; - $sth->execute($report->id, $o1 + $_, $row + $n_header_rows, $data_row->{object}->${ \ $methods->{$row_ident}->[$_] }) for 0 .. $#{ $methods->{$row_ident} }; - $sth->execute($report->id, $o2 + $_, $row + $n_header_rows, $data_row->{raw_data}{ $raw_methods->{$row_ident}->[$_] }) for 0 .. $#{ $raw_methods->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $_, $row + $n_header_rows, $data_row->{info_data}{ $info_methods->{$row_ident}->[$_] }) for 0 .. $#{ $info_methods->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $o1 + $_, $row + $n_header_rows, $data_row->{object}->${ \ $methods->{$row_ident}->[$_] }) for 0 .. $#{ $methods->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $o2 + $_, $row + $n_header_rows, $data_row->{raw_data}{ $raw_methods->{$row_ident}->[$_] }) for 0 .. $#{ $raw_methods->{$row_ident} }; - $sth2->execute($report->id, $row + $n_header_rows, 'information', $_) for @{ $data_row->{information} || [] }; - $sth2->execute($report->id, $row + $n_header_rows, 'errors', $_) for @{ $data_row->{errors} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + $n_header_rows, 'information', $_) for @{ $data_row->{information} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + $n_header_rows, 'errors', $_) for @{ $data_row->{errors} || [] }; } 1; }) or do { die SL::DB->client->error }; @@ -732,4 +728,25 @@ sub init_mappings { [ grep { $_->{from} } @{ $::form->{mappings} || [] } ] } +sub setup_render_inputs_action_bar { + my ($self, %params) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Preview'), + submit => [ '#form', { action => 'CsvImport/test' } ], + accesskey => 'enter', + not_if => ($self->profile && $self->profile->get('dont_edit_profile')), + ], + action => [ + t8('Import'), + submit => [ '#form', { action => 'CsvImport/import' } ], + disabled => t8('The test import has not been executed yet.'), + id => 'action_import', + ], + ); + } +} + 1;