diff --git a/config/app.php b/config/app.php index dbb14420..24775499 100644 --- a/config/app.php +++ b/config/app.php @@ -35,6 +35,7 @@ return [ \Engelsystem\Mail\MailerServiceProvider::class, \Engelsystem\Http\HttpClientServiceProvider::class, \Engelsystem\Helpers\DumpServerServiceProvider::class, + \Engelsystem\Helpers\UuidServiceProvider::class, ], // Application middleware diff --git a/db/migrations/2022_06_03_000000_shifts_add_transaction_id.php b/db/migrations/2022_06_03_000000_shifts_add_transaction_id.php index 79a3c256..2e31c013 100644 --- a/db/migrations/2022_06_03_000000_shifts_add_transaction_id.php +++ b/db/migrations/2022_06_03_000000_shifts_add_transaction_id.php @@ -19,7 +19,7 @@ class ShiftsAddTransactionId extends Migration } $this->schema->table('Shifts', function (Blueprint $table) { - $table->unsignedInteger('transaction_id')->nullable()->default(null); + $table->uuid('transaction_id')->index()->nullable()->default(null); }); } diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index ba3e11b5..3a1f41b6 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -556,19 +556,6 @@ function Shift_update($shift) ); } -/** - * Get the next free shifts transaction id - */ -function Shift_get_next_transaction_id($lock = true): int -{ - $query = Db::connection()->table('Shifts')->select('transaction_id'); - if ($lock) { - $query->lockForUpdate(); - } - - return $query->max('transaction_id') + 1; -} - /** * Create a new shift. * diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index a6603784..14876471 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -5,6 +5,7 @@ use Engelsystem\Helpers\Carbon; use Engelsystem\Http\Exceptions\HttpForbidden; use Engelsystem\Models\Room; use Engelsystem\Models\User\User; +use Illuminate\Support\Str; /** * @return string @@ -365,17 +366,10 @@ function admin_shifts() throw_redirect(page_link_to('admin_shifts')); } - $transactionRunning = true; - Db::connection()->beginTransaction(); - $transactionId = Shift_get_next_transaction_id(); - + $transactionId = Str::uuid(); 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']] @@ -383,6 +377,7 @@ function admin_shifts() . ' with description ' . $shift['description'] . ' from ' . date('Y-m-d H:i', $shift['start']) . ' to ' . date('Y-m-d H:i', $shift['end']) + . ', transaction: ' . $transactionId ); $needed_angel_types_info = []; diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 8f7d0e4f..2a70bccb 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -532,7 +532,7 @@ msgid "Shift deleted." msgstr "Schicht gelöscht." msgid "Shifts history" -msgstr "Schichten historie" +msgstr "Schichten Historie" msgid "%s shifts deleted." msgstr "%s Schichten gelöscht." diff --git a/src/Helpers/UuidServiceProvider.php b/src/Helpers/UuidServiceProvider.php new file mode 100644 index 00000000..dea1dea8 --- /dev/null +++ b/src/Helpers/UuidServiceProvider.php @@ -0,0 +1,34 @@ +register(); + + $this->assertStringMatchesFormat( + '%x%x%x%x%x%x%x%x-%x%x%x%x-4%x%x%x-%x%x%x%x-%x%x%x%x%x%x%x%x%x%x%x%x', + Str::uuid() + ); + } +}