Use locking for shift transacton id generation
This commit is contained in:
parent
96277dcfc4
commit
7c448e6064
|
@ -559,9 +559,14 @@ function Shift_update($shift)
|
|||
/**
|
||||
* Get the next free shifts transaction id
|
||||
*/
|
||||
function Shift_get_next_transaction_id(): int
|
||||
function Shift_get_next_transaction_id($lock = true): int
|
||||
{
|
||||
return Db::selectOne('SELECT MAX(transaction_id) + 1 AS transaction_id FROM Shifts')['transaction_id'] ?? 1;
|
||||
$query = Db::connection()->table('Shifts')->select('transaction_id');
|
||||
if ($lock) {
|
||||
$query->lockForUpdate();
|
||||
}
|
||||
|
||||
return $query->max('transaction_id') + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -365,10 +365,17 @@ function admin_shifts()
|
|||
throw_redirect(page_link_to('admin_shifts'));
|
||||
}
|
||||
|
||||
$transactionRunning = true;
|
||||
Db::connection()->beginTransaction();
|
||||
$transactionId = Shift_get_next_transaction_id();
|
||||
|
||||
foreach ($session->get('admin_shifts_shifts', []) as $shift) {
|
||||
$shift['URL'] = null;
|
||||
$shift_id = Shift_create($shift, $transactionId);
|
||||
if ($transactionRunning) {
|
||||
$transactionRunning = false;
|
||||
Db::connection()->commit();
|
||||
}
|
||||
|
||||
engelsystem_log(
|
||||
'Shift created: ' . $shifttypes[$shift['shifttype_id']]
|
||||
|
|
Loading…
Reference in New Issue