CreatePeriodicInvoices: Transaktionssicher
[kivitendo-erp.git] / SL / BackgroundJob / CreatePeriodicInvoices.pm
index b7b3e33..6cfdf94 100644 (file)
@@ -28,6 +28,8 @@ sub run {
   $self->{db_obj} = shift;
 
   $self->{job_errors} = [];
+  if (!$self->{db_obj}->db->with_transaction(sub {
+    1;                          # make Emacs happy
 
   my $configs = SL::DB::Manager::PeriodicInvoicesConfig->get_all(query => [ active => 1 ]);
 
@@ -81,6 +83,12 @@ sub run {
                              \@disabled_orders  ,
   );
 
+    1;
+  })) {
+    $::lxdebug->message(LXDebug->WARN(), "_create_invoice failed: " . join("\n", (split(/\n/, $self->{db_obj}->db->error))[0..2]));
+    return undef;
+  }
+
   if (@{ $self->{job_errors} }) {
     my $msg = join "\n", @{ $self->{job_errors} };
     _log_msg("Errors: $msg");