Reune comparacao e qualificacao em relatorio de conferencia imprimivel
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\ProcurementReviewReport;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\Events\QueryExecuted;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
|
||||
require __DIR__.'/../../vendor/autoload.php';
|
||||
$database = $argv[1] ?? '';
|
||||
if (! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/', $database)) {
|
||||
throw new LogicException('Base de teste inválida.');
|
||||
}
|
||||
$app = require __DIR__.'/../../bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
if (! $app->environment('testing') || DB::connection()->getDatabaseName() !== $database) {
|
||||
throw new LogicException('Worker não isolado.');
|
||||
}
|
||||
DB::select('select set_config(?, ?, false)', ['application_name', 'sgc_review_report']);
|
||||
$actor = User::query()->findOrFail($argv[2]);
|
||||
auth()->guard()->setUser($actor);
|
||||
$lock = (int) $argv[4];
|
||||
$proof = null;
|
||||
if ($argv[5] === 'consistent_snapshot') {
|
||||
$paused = false;
|
||||
DB::listen(function (QueryExecuted $query) use ($lock, &$proof, &$paused) {
|
||||
if (! $paused && str_contains($query->sql, 'from "qualification_sets"')) {
|
||||
$paused = true;
|
||||
$proof = DB::selectOne("select current_setting('transaction_isolation') as isolation, current_setting('transaction_read_only') as read_only");
|
||||
DB::select('select pg_advisory_xact_lock(?)', [$lock]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Cache the authenticated actor before the parent revokes role/department.
|
||||
DB::select('select pg_advisory_lock(?)', [$lock]);
|
||||
DB::select('select pg_advisory_unlock(?)', [$lock]);
|
||||
}
|
||||
try {
|
||||
$report = app(ProcurementReviewReport::class)->build($actor, (int) $argv[3]);
|
||||
$status = 200;
|
||||
} catch (HttpExceptionInterface $exception) {
|
||||
$status = $exception->getStatusCode();
|
||||
$report = null;
|
||||
} catch (ModelNotFoundException) {
|
||||
$status = 404;
|
||||
$report = null;
|
||||
}
|
||||
echo json_encode(['status' => $status, 'report' => $report, 'proof' => $proof], JSON_THROW_ON_ERROR);
|
||||
Reference in New Issue
Block a user