Files
Investidor-V2/tools/demography-release-status.php
T
2026-11-21 20:58:19 +02:00

35 lines
2.1 KiB
PHP

<?php
use App\Services\DemographicInstallation;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Contracts\Http\Kernel as HttpKernel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
require dirname(__DIR__).'/vendor/autoload.php';
$app = require dirname(__DIR__).'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
throw_unless(app(DemographicInstallation::class)->activeTarget(), RuntimeException::class, 'Operational identity differs.');
$installed = Schema::hasTable('demographic_observations');
$proof = ['target' => ['database' => 'investemoz', 'port' => 5432], 'installed' => $installed,
'observations' => $installed ? DB::table('demographic_observations')->count() : 0,
'approved_batches' => $installed ? DB::table('demographic_imports')->where('status', 'approved')->count() : 0,
'authenticated_operation_recorded' => DB::table('audit_events')->where('source_system', 'demography-installation')->where('action', 'install_and_import')->exists(),
'routes' => [], 'at' => gmdate(DATE_ATOM), 'scope' => 'Application kernel smoke test, not a browser or TLS certification'];
foreach (['/management/demography/install', '/localizacoes/demografia', '/api/v1/investment/demography'] as $path) {
$request = Request::create('https://portal-investidor.test'.$path, 'GET');
if (str_starts_with($path, '/api/')) {
$request->headers->set('Accept', 'application/json');
}
$response = $app->make(HttpKernel::class)->handle($request);
$row = ['path' => $path, 'status' => $response->getStatusCode()];
if (str_starts_with($path, '/api/')) {
$row['state'] = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR)['state'] ?? null;
}
$proof['routes'][] = $row;
throw_unless(in_array($response->getStatusCode(), str_starts_with($path, '/management/') ? [302, 303] : [200], true), RuntimeException::class, 'Published route failed.');
}
file_put_contents(base_path('outputs/demography-20261113/operational-status.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode($proof, JSON_THROW_ON_ERROR).PHP_EOL;