Files
Investidor-V2/tools/portal-service-followup-active-queue.php
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

42 lines
3.3 KiB
PHP

<?php
// Destination READ ONLY. No providers, unserialization, worker, mail or database writes.
ini_set('zend.exception_ignore_args', '1');
$root = dirname(__DIR__);
require $root.'/vendor/autoload.php';
$app = require $root.'/bootstrap/app.php';
(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);
(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
$c = config('database.connections.'.config('database.default'));
throw_unless($c['driver'] === 'pgsql' && empty($c['url']) && in_array($c['host'], ['127.0.0.1', 'localhost'], true)
&& (int) $c['port'] === 5432 && $c['database'] === 'investemoz', RuntimeException::class, 'Exact read-only destination required');
$pdo = new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz', $c['username'], $c['password'], [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$pdo->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');
throw_unless($pdo->query('SELECT current_database()')->fetchColumn() === 'investemoz' && (int) $pdo->query('SELECT inet_server_port()')->fetchColumn() === 5432, RuntimeException::class);
$groups = [];
foreach ($pdo->query('SELECT queue,payload,reserved_at,attempts FROM jobs')->fetchAll(PDO::FETCH_ASSOC) as $job) {
$payload = json_decode($job['payload'], true, 512, JSON_THROW_ON_ERROR);
$class = $payload['data']['commandName'] ?? $payload['displayName'] ?? 'unknown';
if (! is_string($class) || ! preg_match('/^[A-Za-z0-9_\\\\]+$/D', $class)) $class = 'unknown';
$key = $job['queue'].'|'.$class;
$groups[$key] ??= ['queue' => $job['queue'], 'class' => $class, 'count' => 0, 'reserved' => 0, 'retried' => 0];
$groups[$key]['count']++;
$groups[$key]['reserved'] += $job['reserved_at'] !== null ? 1 : 0;
$groups[$key]['retried'] += (int) $job['attempts'] > 0 ? 1 : 0;
}
$failed = (int) $pdo->query('SELECT count(*) FROM failed_jobs')->fetchColumn();
$pdo->exec('ROLLBACK');
$effects = [
'App\\Jobs\\ScanDocumentForMalware' => 'SQL/document audit and private storage; local ClamD socket. No publication or mail.',
'App\\Jobs\\RunSimulation' => 'Simulation execution and persistence; inspect scenario/calculation scope before starting.',
'App\\Jobs\\NotifyInterestReceived' => 'Possible outbound email when notifications are enabled and recipients configured; never execute during preparation.',
'App\\Jobs\\CompareMneBusiness' => 'Read existing-business and canonical repositories; writes sanitized comparison telemetry. No mail.',
];
$proof = ['at' => gmdate('c'), 'target' => 'investemoz:5432', 'read_only' => true, 'providers_booted' => false,
'pending_by_class' => array_values($groups), 'failed_jobs' => $failed, 'known_consumers' => $effects,
'effective_notifications_enabled' => (bool) config('portal.notifications_enabled'),
'configured_notification_recipient_count' => count(config('portal.notification_recipients', [])),
'queue_driver' => config('queue.default'), 'queue' => config('queue.connections.database.queue'),
'mail_transport' => config('mail.default'), 'active_jobs_consumed' => 0, 'active_writes' => 0];
file_put_contents($root.'/storage/app/private/investmoz-v2/portal-audit/service-followup-active-queue-readonly.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode($proof, JSON_THROW_ON_ERROR).PHP_EOL;