make(Kernel::class)->bootstrap(); portalQaAssertTarget($target); $directory = storage_path('app/private/investmoz-v2/portal-audit'); $browser = json_decode(file_get_contents($directory.'/legacy-content-browser-qa.json'), true, 512, JSON_THROW_ON_ERROR); if (($browser['result'] ?? null) !== 'passed' || ($browser['target'] ?? null) !== $target['database'].':55441') { throw new RuntimeException('Completed browser proof on the same QA required.'); } DB::beginTransaction(); try { DB::statement('SET TRANSACTION READ ONLY'); $case = DB::table('desk_cases')->where('id', $browser['dossier_id'])->firstOrFail(); $payload = app(VirtualDesk::class)->decode($case->payload); $references = $payload['investor_path']['content_sources'] ?? []; $events = DB::table('desk_events')->where('case_id', $case->id)->where('action', 'legacy_content_referenced')->count(); if ((int) $case->user_id !== 21 || count($references) !== 1 || $events !== 1 || (int) $references[0]['resource_id'] !== 6) { throw new RuntimeException('Browser association is not isolated/idempotent.'); } $resources = DB::table('portal_resources as r')->join('documents as d', 'd.id', '=', 'r.document_id') ->whereIn('r.id', [5, 6])->get(['r.id', 'r.published', 'r.metadata_version', 'd.sha256', 'd.storage_key', 'd.malware_scan_status', 'd.malware_scanned_sha256']); $originals = []; foreach ($resources as $row) { $sha = trim($row->sha256); $file = Storage::disk('local')->path($row->storage_key); $verified = hash_equals($sha, hash_file('sha256', $file)); $duplicates = DB::table('documents')->where('sha256', $row->sha256)->whereNull('deleted_at')->count(); if (! $verified || $duplicates !== 1 || ! $row->published || $row->malware_scan_status !== 'clean' || ! hash_equals($sha, trim($row->malware_scanned_sha256))) { throw new RuntimeException('Original/public resource integrity changed.'); } $originals[] = ['resource_id' => $row->id, 'original_hash_verified' => true, 'same_bytes_as_scan' => true, 'document_count_for_hash' => $duplicates, 'metadata_version' => $row->metadata_version]; } $http = json_decode(file_get_contents($directory.'/legacy-content-http-qa.json'), true, 512, JSON_THROW_ON_ERROR); $independent = DB::table('desk_cases')->where('id', $http['dossier']['independent_id'])->firstOrFail(); $independentPayload = app(VirtualDesk::class)->decode($independent->payload); if (($independentPayload['investor_path']['content_sources'] ?? []) !== []) { throw new RuntimeException('Unexpected reference in independent project.'); } $result = ['verified_at' => now()->toIso8601String(), 'target' => $target['database'].':55441', 'transaction_read_only' => true, 'actor_id' => 21, 'dossier_id' => $case->id, 'version' => $case->version, 'reference_count' => count($references), 'reference_event_count' => $events, 'originals' => $originals, 'independent_project_reference_count' => 0, 'active_access' => false, 'database_writes' => 0]; file_put_contents($directory.'/legacy-content-browser-persistence-qa.json', json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); echo json_encode($result, JSON_UNESCAPED_UNICODE); } finally { DB::rollBack(); }