Revision 96670fe8
Von Moritz Bunkus vor etwa 8 Jahren hinzugefügt
SL/Controller/Buchungsgruppen.pm | ||
---|---|---|
85 | 85 |
# allow deletion of unused Buchungsgruppen. Will fail, due to database |
86 | 86 |
# constraint, if Buchungsgruppe is connected to a part |
87 | 87 |
|
88 |
my $db = $self->{config}->db; |
|
89 |
$db->do_transaction(sub { |
|
90 |
my $taxzone_charts = SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->config->id ]); |
|
91 |
foreach my $taxzonechart ( @{$taxzone_charts} ) { $taxzonechart->delete }; |
|
92 |
$self->config->delete(); |
|
93 |
flash_later('info', $::locale->text('The booking group has been deleted.')); |
|
88 |
$self->{config}->db->with_transaction(sub { |
|
89 |
my $taxzone_charts = SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->config->id ]); |
|
90 |
foreach my $taxzonechart ( @{$taxzone_charts} ) { $taxzonechart->delete }; |
|
91 |
$self->config->delete(); |
|
92 |
flash_later('info', $::locale->text('The booking group has been deleted.')); |
|
93 |
|
|
94 |
1; |
|
94 | 95 |
}) || flash_later('error', $::locale->text('The booking group is in use and cannot be deleted.')); |
95 | 96 |
|
96 | 97 |
$self->redirect_to(action => 'list'); |
... | ... | |
133 | 134 |
my @errors; |
134 | 135 |
|
135 | 136 |
my $db = $self->config->db; |
136 |
$db->do_transaction( sub {
|
|
137 |
if (!$db->with_transaction(sub {
|
|
137 | 138 |
|
138 | 139 |
$self->config->assign_attributes(%{ $params }); # assign description and inventory_accno_id |
139 | 140 |
|
... | ... | |
169 | 170 |
$taxzone_chart->save; |
170 | 171 |
} |
171 | 172 |
} |
172 |
} ) || die @errors ? join("\n", @errors) . "\n" : $db->error . "\n"; |
|
173 |
# die with rollback of taxzone save if saving of any of the taxzone_charts fails |
|
174 |
# only show the $db->error if we haven't already identified the likely error ourselves |
|
173 |
|
|
174 |
1; |
|
175 |
})) { |
|
176 |
die @errors ? join("\n", @errors) . "\n" : $db->error . "\n"; |
|
177 |
# die with rollback of taxzone save if saving of any of the taxzone_charts fails |
|
178 |
# only show the $db->error if we haven't already identified the likely error ourselves |
|
179 |
} |
|
175 | 180 |
|
176 | 181 |
flash_later('info', $is_new ? t8('The booking group has been created.') : t8('The booking group has been saved.')); |
177 | 182 |
$self->redirect_to(action => 'list'); |
Auch abrufbar als: Unified diff
»with_transaction« anstelle von »do_transaction« verwenden
Es sollte so selten wie möglich »do_transaction« verwndet werden, damit
man sich immer angewöhnt, »with_transaction« zu nutzen.
Hintergründe und Unterschiede zwischen den beiden Funktionen sind in der
Dokumentation von SL/DB.pm beschrieben.