31 lines
3.9 KiB
PHP
31 lines
3.9 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args', '1');
|
|
set_exception_handler(function (Throwable $e) { fwrite(STDERR, 'QA inspection stopped: '.$e::class.' line '.$e->getLine().PHP_EOL); exit(1); });
|
|
$db = new PDO('pgsql:host=127.0.0.1;port=55441;dbname=stability_consumers_20261011_084534_test', 'postgres', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
|
|
$db->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');
|
|
try {
|
|
$identity = $db->query('SELECT current_database() AS database,inet_server_port() AS port')->fetch(PDO::FETCH_ASSOC);
|
|
if ($identity['database'] !== 'stability_consumers_20261011_084534_test' || (int) $identity['port'] !== 55441) throw new RuntimeException('Isolated QA identity mismatch');
|
|
$id = '172aa874-98fc-4bf6-b78f-d2e9a386d345';
|
|
$query = $db->prepare('SELECT id,code,modality,status,version_no,classification,owner_user_id,organization_id,sector_id,public_slug,published_at,expires_at FROM existing_businesses WHERE id=? AND deleted_at IS NULL');
|
|
$query->execute([$id]); $record = $query->fetch(PDO::FETCH_ASSOC);
|
|
if (!$record) throw new RuntimeException('Expected existing QA record missing');
|
|
$counts = []; $hashes = [];
|
|
foreach (['existing_business_revisions' => 'business_id', 'existing_business_reviews' => 'business_id', 'existing_business_objects' => 'business_id', 'existing_business_mandates' => 'business_id', 'existing_business_document_links' => 'existing_business_id', 'existing_business_locations' => 'existing_business_id', 'business_workflow_transitions' => 'existing_business_id'] as $table => $foreign) {
|
|
$sql = 'SELECT row_to_json(t)::text FROM "'.$table.'" t WHERE "'.$foreign.'"=? ORDER BY row_to_json(t)::text';
|
|
$q = $db->prepare($sql); $q->execute([$id]); $rows = $q->fetchAll(PDO::FETCH_COLUMN);
|
|
$counts[$table] = count($rows); $hashes[$table] = hash('sha256', implode("\n", $rows));
|
|
}
|
|
$q = $db->prepare('SELECT version_no,action,sha256 FROM existing_business_revisions WHERE business_id=? ORDER BY version_no');
|
|
$q->execute([$id]); $history = $q->fetchAll(PDO::FETCH_ASSOC);
|
|
$q = $db->prepare('SELECT sha256 FROM documents WHERE id IN (SELECT document_id FROM existing_business_document_links WHERE existing_business_id=? UNION SELECT document_id FROM existing_business_mandates WHERE business_id=?) ORDER BY id');
|
|
$q->execute([$id,$id]); $documentHashes = $q->fetchAll(PDO::FETCH_COLUMN);
|
|
$columns = $db->query("SELECT table_name,column_name,data_type FROM information_schema.columns WHERE table_schema='public' AND table_name IN ('existing_businesses','existing_business_revisions','existing_business_document_links') ORDER BY table_name,ordinal_position")->fetchAll(PDO::FETCH_ASSOC);
|
|
$profiles = $db->query("SELECT u.id,u.name,r.role,r.organization_id,r.opportunity_types,r.responsibilities,r.revoked_at,r.starts_at,r.expires_at FROM users u JOIN portal_role_assignments r ON r.user_id=u.id WHERE u.name LIKE 'QA profiles v1%' ORDER BY u.id,r.role")->fetchAll(PDO::FETCH_ASSOC);
|
|
$safeProfiles = array_map(fn($r) => array_diff_key($r,['name'=>true]),$profiles);
|
|
$proof = ['at'=>gmdate('c'),'target'=>$identity,'SQL_read_only'=>true,'record'=>$record,'related_counts'=>$counts,'related_hashes'=>$hashes,'revisions'=>$history,'linked_document_hashes'=>$documentHashes,'columns'=>$columns,'existing_QA_profile_assignments'=>$safeProfiles,'active_changes'=>0,'QA_writes'=>0,'accepted_tests_repeated'=>false,'payload_decrypted'=>false];
|
|
if (is_file(__DIR__.'/ESTADO-QA-READONLY.json')) throw new RuntimeException('Preserve existing inspection');
|
|
file_put_contents(__DIR__.'/ESTADO-QA-READONLY.json', json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode(['record'=>$record,'related_counts'=>$counts,'revision_count'=>count($history),'document_count'=>count($documentHashes),'QA_profile_rows'=>count($safeProfiles),'read_only'=>true,'active_changes'=>0],JSON_UNESCAPED_UNICODE).PHP_EOL;
|
|
} finally { $db->exec('ROLLBACK'); }
|