1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Improve try/catch with transaction rollbacks

This commit is contained in:
David Bomba 2024-10-01 13:03:28 +10:00
parent 8f793ea861
commit 4ef2ff9bae
4 changed files with 5 additions and 26 deletions

View File

@ -294,8 +294,6 @@ class MatchBankTransactions implements ShouldQueue
$this->attachable_invoices = [];
$this->available_balance = $amount;
nlog($invoices->count());
\DB::connection(config('database.default'))->transaction(function () use ($invoices) {
$invoices->each(function ($invoice) {
$this->invoice = Invoice::withTrashed()->where('id', $invoice->id)->lockForUpdate()->first();
@ -329,8 +327,6 @@ class MatchBankTransactions implements ShouldQueue
});
}, 2);
nlog("pre");
// @phpstan-ignore-next-line
if (!$this->invoice) {
return;

View File

@ -46,6 +46,7 @@ class MultiDB
public const DB_PREFIX = 'db-ninja-';
public static $dbs = ['db-ninja-01', 'db-ninja-02'];
// public static $dbs = ['db-ninja-01', 'db-ninja-02', 'db-ninja-03'];
private static $protected_domains = [
'www',

View File

@ -16,7 +16,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class UpdateContactLastLogin implements ShouldQueue
{
public $delay = 8;
/**
* Create the event listener.
*
@ -37,8 +36,8 @@ class UpdateContactLastLogin implements ShouldQueue
MultiDB::setDb($event->company->db);
$client_contact = $event->client_contact;
$client_contact->last_login = now();
$client_contact->save();
}
}

View File

@ -89,12 +89,7 @@ class ClientService
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $exception) {
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
}
return $this;
}
@ -115,13 +110,7 @@ class ClientService
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $exception) {
nlog("DB ERROR " . $exception->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
}
return $this;
}
@ -141,13 +130,7 @@ class ClientService
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $exception) {
nlog("DB ERROR " . $exception->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
}
return $this;
}