X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport.pm;h=43d6fbf7ad95d4737b44f692184714344b933a79;hb=f1adac26732c78610767856db26d76d889e04f71;hp=86cecfe57470b8b521d7a24f51085cc7089a54a9;hpb=8e926112ea0e2f73c096c82987ae29f7078049c3;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 86cecfe57..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; @@ -40,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'); @@ -98,7 +99,6 @@ sub action_result { my $data = $self->{background_job}->data_as_hash; my $profile = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id}); - $self->profile($profile); if ($data->{errors} and my $first_error = $data->{errors}->[0]) { @@ -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,7 +266,8 @@ sub action_add_mapping_from_upload { # sub check_auth { - $::auth->assert('config'); + $_[0]->check_type; + $_[0]->worker->check_auth; } sub check_type { @@ -333,6 +333,8 @@ sub render_inputs { $self->setup_help; + $self->setup_render_inputs_action_bar; + $self->render('csv_import/form', title => $title); } @@ -414,7 +416,7 @@ sub load_default_profile { my $profile; if ($::form->{profile}->{id}) { - $profile = SL::DB::Manager::CsvImportProfile->find_by(id => $::form->{profile}->{id}, login => $::myconfig{login}); + $profile = SL::DB::Manager::CsvImportProfile->find_by(id => $::form->{profile}->{id}); } $profile ||= SL::DB::Manager::CsvImportProfile->find_by(type => $self->{type}, is_default => 1, login => $::myconfig{login}); $profile ||= SL::DB::CsvImportProfile->new(type => $self->{type}, login => $::myconfig{login}); @@ -544,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; @@ -554,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 }; @@ -623,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 @@ -647,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 }; @@ -726,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;