23 lines
1.5 KiB
PHP
23 lines
1.5 KiB
PHP
<?php
|
|
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
$app = require __DIR__.'/../bootstrap/app.php';
|
|
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
\App\Shared\Testing\TestingDatabaseGuard::assertSafe();
|
|
$input = json_decode(stream_get_contents(STDIN), true, 32, JSON_THROW_ON_ERROR);
|
|
$context = app(\App\Shared\Context\CompanyContext::class);
|
|
$context->selectFor($input['actor'], $input['tenant'], $input['company'], $input['unit']);
|
|
try {
|
|
$result = \Illuminate\Support\Facades\DB::transaction(function () use ($input) {
|
|
if ($input['hold'] ?? false) {
|
|
\Illuminate\Support\Facades\DB::table('companies')->where('id', $input['company'])->lockForUpdate()->firstOrFail();
|
|
echo "LOCK_ACQUIRED\n"; flush(); usleep(2000000);
|
|
}
|
|
if (($input['operation'] ?? '') === 'b1.confirm') { return app(\App\Modules\Services\InternalConfirmation::class)->confirm($input['id'], $input['actor'], $input['version'], $input['key']); }
|
|
return app(\App\Modules\Services\ServiceWorkflow::class)->save('clients', $input['id'] ?? null, $input['actor'], $input['data'], $input['key']);
|
|
});
|
|
echo json_encode(['status' => 200, 'result' => $result], JSON_THROW_ON_ERROR).PHP_EOL;
|
|
} catch (\Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception) {
|
|
echo json_encode(['status' => $exception->getStatusCode()], JSON_THROW_ON_ERROR).PHP_EOL;
|
|
} catch (\Throwable) { fwrite(STDERR, "Synthetic concurrency worker failed; no request payload displayed.\n"); exit(1); }
|