From: Sven Schöling Date: Tue, 6 Nov 2012 16:01:19 +0000 (+0100) Subject: CsvReport: Status mitspeichern X-Git-Tag: release-3.1.0beta1~744 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a5a42ed1bf23da4a35b675ce00781fea99df2acd;p=kivitendo-erp.git CsvReport: Status mitspeichern --- diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 5171576eb..830d5ff77 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -276,9 +276,11 @@ sub save_report { my $dbh = $::form->get_standard_dbh; $dbh->begin_work; - my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)'; + my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)'; + my $query2 = 'INSERT INTO csv_import_report_status (csv_import_report_id, row, type, value) VALUES (?, ?, ?, ?)'; my $sth = $dbh->prepare($query); + my $sth2 = $dbh->prepare($query2); # save headers my @headers = ( @@ -302,6 +304,9 @@ sub save_report { $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; + + $sth2->execute($report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] }; + $sth2->execute($report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] }; } $dbh->commit; diff --git a/SL/DB/CsvImportReport.pm b/SL/DB/CsvImportReport.pm index 879c0404c..38d9e697e 100644 --- a/SL/DB/CsvImportReport.pm +++ b/SL/DB/CsvImportReport.pm @@ -13,6 +13,11 @@ __PACKAGE__->meta->add_relationships( class => 'SL::DB::CsvImportReportRow', column_map => { id => 'csv_import_report_id' }, }, + status => { + type => 'one to many', + class => 'SL::DB::CsvImportReportStatus', + column_map => { id => 'csv_import_report_id' }, + }, ); __PACKAGE__->meta->make_manager_class; @@ -26,16 +31,35 @@ sub folded_rows { return $self->{folded_rows}; } +sub folded_status { + my ($self) = @_; + + $self->_fold_status unless $self->{folded_status}; + + return $self->{folded_status}; +} + sub _fold_rows { my ($self) = @_; $self->{folded_rows} = []; for my $row_obj (@{ $self->rows }) { - $::lxdebug->dump(0, "adding", $row_obj->row . ' ' . $row_obj->col . ' ' . $row_obj->value); $self->{folded_rows}->[ $row_obj->row ] ||= []; $self->{folded_rows}->[ $row_obj->row ][ $row_obj->col ] = $row_obj->value; - $::lxdebug->dump(0, "now", $self->{folded_rows}); + } +} + +sub _fold_status { + my ($self) = @_; + + $self->{folded_status} = []; + + for my $status_obj (@{ $self->status }) { + $self->{folded_status}->[ $status_obj->row ] ||= {}; + $self->{folded_status}->[ $status_obj->row ]{information} ||= []; + $self->{folded_status}->[ $status_obj->row ]{errors} ||= []; + push @{ $self->{folded_status}->[ $status_obj->row ]{ $status_obj->type } }, $status_obj->value; } } diff --git a/SL/DB/CsvImportReportRowStatus.pm b/SL/DB/CsvImportReportRowStatus.pm deleted file mode 100644 index 495169185..000000000 --- a/SL/DB/CsvImportReportRowStatus.pm +++ /dev/null @@ -1,13 +0,0 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - -package SL::DB::CsvImportReportRowStatus; - -use strict; - -use SL::DB::MetaSetup::CsvImportReportRowStatus; - -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; - -1; diff --git a/SL/DB/CsvImportReportStatus.pm b/SL/DB/CsvImportReportStatus.pm new file mode 100644 index 000000000..68a041b4c --- /dev/null +++ b/SL/DB/CsvImportReportStatus.pm @@ -0,0 +1,13 @@ +# This file has been auto-generated only because it didn't exist. +# Feel free to modify it at will; it will not be overwritten automatically. + +package SL::DB::CsvImportReportStatus; + +use strict; + +use SL::DB::MetaSetup::CsvImportReportStatus; + +# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. +__PACKAGE__->meta->make_manager_class; + +1; diff --git a/SL/DB/Helper/Mappings.pm b/SL/DB/Helper/Mappings.pm index 138807437..d04d05e1b 100644 --- a/SL/DB/Helper/Mappings.pm +++ b/SL/DB/Helper/Mappings.pm @@ -52,7 +52,7 @@ my %lxoffice_package_names = ( csv_import_profile_settings => 'csv_import_profile_setting', csv_import_reports => 'csv_import_report', csv_import_report_rows => 'csv_import_report_row', - csv_import_report_row_status => 'csv_import_report_row_status', + csv_import_report_status => 'csv_import_report_status', custom_variable_configs => 'custom_variable_config', custom_variables => 'custom_variable', custom_variables_validity => 'custom_variable_validity', diff --git a/SL/DB/MetaSetup/CsvImportReportRowStatus.pm b/SL/DB/MetaSetup/CsvImportReportRowStatus.pm deleted file mode 100644 index f0f55f797..000000000 --- a/SL/DB/MetaSetup/CsvImportReportRowStatus.pm +++ /dev/null @@ -1,30 +0,0 @@ -# This file has been auto-generated. Do not modify it; it will be overwritten -# by rose_auto_create_model.pl automatically. -package SL::DB::CsvImportReportRowStatus; - -use strict; - -use base qw(SL::DB::Object); - -__PACKAGE__->meta->setup( - table => 'csv_import_report_row_status', - - columns => [ - id => { type => 'serial', not_null => 1 }, - csv_import_report_row_id => { type => 'integer', not_null => 1 }, - type => { type => 'text', not_null => 1 }, - value => { type => 'text' }, - ], - - primary_key_columns => [ 'id' ], - - foreign_keys => [ - csv_import_report_row => { - class => 'SL::DB::CsvImportReportRow', - key_columns => { csv_import_report_row_id => 'id' }, - }, - ], -); - -1; -; diff --git a/SL/DB/MetaSetup/CsvImportReportStatus.pm b/SL/DB/MetaSetup/CsvImportReportStatus.pm new file mode 100644 index 000000000..ef9d30354 --- /dev/null +++ b/SL/DB/MetaSetup/CsvImportReportStatus.pm @@ -0,0 +1,24 @@ +# This file has been auto-generated. Do not modify it; it will be overwritten +# by rose_auto_create_model.pl automatically. +package SL::DB::CsvImportReportStatus; + +use strict; + +use base qw(SL::DB::Object); + +__PACKAGE__->meta->setup( + table => 'csv_import_report_status', + + columns => [ + id => { type => 'serial', not_null => 1 }, + csv_import_report_id => { type => 'integer', not_null => 1 }, + row => { type => 'integer', not_null => 1 }, + type => { type => 'text', not_null => 1 }, + value => { type => 'text' }, + ], + + primary_key_columns => [ 'id' ], +); + +1; +; diff --git a/sql/Pg-upgrade2/csv_import_report_cache.sql b/sql/Pg-upgrade2/csv_import_report_cache.sql index 440c34610..e401b8397 100644 --- a/sql/Pg-upgrade2/csv_import_report_cache.sql +++ b/sql/Pg-upgrade2/csv_import_report_cache.sql @@ -19,9 +19,10 @@ CREATE TABLE csv_import_report_rows ( value TEXT ); -CREATE TABLE csv_import_report_row_status ( +CREATE TABLE csv_import_report_status ( id SERIAL PRIMARY KEY, - csv_import_report_row_id INTEGER NOT NULL REFERENCES csv_import_report_rows(id), + csv_import_report_id INTEGER NOT NULL REFERENCES csv_import_reports(id), + row INTEGER NOT NULL, type TEXT NOT NULL, value TEXT ); diff --git a/templates/webpages/csv_import/report.html b/templates/webpages/csv_import/report.html index 7965b092f..e6c34b004 100644 --- a/templates/webpages/csv_import/report.html +++ b/templates/webpages/csv_import/report.html @@ -14,13 +14,14 @@ [%- LxERP.t8('Notes') %] [%- ELSE %] - + [% csv_import_report_errors = SELF.report.folded_status.${loop.index}.errors %] + [%- FOREACH value = row %] [%- value | html %] [%- END %] - [%- FOREACH error = row.errors %][%- HTML.escape(error) %][% UNLESS loop.last %]
[%- END %][%- END %] - [%- FOREACH info = row.information %][% IF !loop.first || row.errors.size %]
[%- END %][%- HTML.escape(info) %][%- END %] + [%- FOREACH error = csv_import_report_errors %][%- error | html %][% UNLESS loop.last %]
[%- END %][%- END %] + [%- FOREACH info = SELF.report.folded_status.${loop.index}.information %][% IF !loop.first || csv_import_report_errors.size %]
[%- END %][%- info | html %][%- END %] [%- END %]