1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
4 package SL::DB::CsvImportReport;
10 use SL::DB::MetaSetup::CsvImportReport;
11 use SL::DB::Manager::CsvImportReport;
13 __PACKAGE__->meta->add_relationships(
15 type => 'one to many',
16 class => 'SL::DB::CsvImportReportRow',
17 column_map => { id => 'csv_import_report_id' },
20 type => 'one to many',
21 class => 'SL::DB::CsvImportReportStatus',
22 column_map => { id => 'csv_import_report_id' },
26 __PACKAGE__->meta->initialize;
29 my ($self, %params) = @_;
33 for my $row_obj (@{ $params{rows} || $self->rows }) {
34 $folded_rows->{ $row_obj->row } ||= [];
35 $folded_rows->{ $row_obj->row }[ $row_obj->col ] = $row_obj->value;
42 my ($self, %params) = @_;
44 my $folded_status = {};
46 for my $status_obj (@{ $params{status} || $self->status }) {
47 $folded_status->{ $status_obj->row } ||= {};
48 $folded_status->{ $status_obj->row }{information} ||= [];
49 $folded_status->{ $status_obj->row }{errors} ||= [];
50 push @{ $folded_status->{ $status_obj->row }{ $status_obj->type } }, $status_obj->value;
56 # implementes cascade delete as per documentation
60 SL::DB->client->with_transaction(sub {
61 my $dbh = SL::DB->client->dbh;
63 do_query($::form, $dbh, 'DELETE FROM csv_import_report_status WHERE csv_import_report_id = ?', $self->id);
64 do_query($::form, $dbh, 'DELETE FROM csv_import_report_rows WHERE csv_import_report_id = ?', $self->id);
65 do_query($::form, $dbh, 'DELETE FROM csv_import_reports WHERE id = ?', $self->id);
67 if ($self->profile_id) {
68 my ($is_profile_used_elsewhere) = selectfirst_array_query($::form, $dbh, <<SQL, $self->profile_id);
70 FROM csv_import_reports
75 if (!$is_profile_used_elsewhere) {
76 do_query($::form, $dbh, 'DELETE FROM csv_import_profile_settings WHERE csv_import_profile_id = ?', $self->profile_id);
77 do_query($::form, $dbh, 'DELETE FROM csv_import_profiles WHERE id = ?', $self->profile_id);
81 }) or do { die SL::DB->client->error };