41 lines
2.7 KiB
PHP
41 lines
2.7 KiB
PHP
<?php
|
|
|
|
use App\Services\VirtualDesk;
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
require_once __DIR__.'/portal-qa-environment.php';
|
|
$target = portalQaEnvironment();
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
$app = require dirname(__DIR__).'/bootstrap/app.php';
|
|
$app->make(Kernel::class)->bootstrap();
|
|
portalQaAssertTarget($target);
|
|
$private = storage_path('app/private/investmoz-v2/portal-audit');
|
|
$receipt = json_decode(file_get_contents($private.'/legacy-content-http-qa.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$ids = [$receipt['public']['resource_id'], $receipt['public']['image_resource_id']];
|
|
$rows = DB::table('portal_resources as r')->join('documents as d', 'd.id', '=', 'r.document_id')
|
|
->whereIn('r.id', $ids)->get(['r.id', 'r.source_url', 'r.published', 'r.metadata_version', 'r.rights_status',
|
|
'd.id as document_id', 'd.external_id', 'd.media_type', 'd.sha256', 'd.malware_scan_status', 'd.malware_scanned_sha256',
|
|
'd.malware_engine', 'd.malware_engine_version', 'd.malware_scanned_at', 'd.data_classification', 'd.storage_key']);
|
|
$result = ['target' => $target, 'resources' => [], 'dossiers' => [], 'active_writes' => 0, 'interface_observed' => false];
|
|
foreach ($rows as $row) {
|
|
$path = Storage::disk('local')->path($row->storage_key);
|
|
unset($row->storage_key);
|
|
$row->original_hash_verified = hash_equals(trim($row->sha256), hash_file('sha256', $path));
|
|
$row->duplicate_document_count = DB::table('documents')->where('sha256', $row->sha256)->whereNull('deleted_at')->count();
|
|
$row->audit_actions = DB::table('audit_events')->where('entity_type', 'portal_resources')->whereRaw("after_data->>'record_id' = ?", [(string) $row->id])->pluck('action');
|
|
$result['resources'][] = $row;
|
|
}
|
|
foreach (['id', 'independent_id', 'continue_id'] as $key) {
|
|
$case = DB::table('desk_cases')->where('id', $receipt['dossier'][$key])->firstOrFail();
|
|
$payload = app(VirtualDesk::class)->decode($case->payload);
|
|
$result['dossiers'][$key] = ['id' => $case->id, 'user_id' => $case->user_id, 'version' => $case->version,
|
|
'reference_count' => count($payload['investor_path']['content_sources'] ?? []),
|
|
'event_count' => DB::table('desk_events')->where('case_id', $case->id)->where('action', 'legacy_content_referenced')->count()];
|
|
}
|
|
$result['totals'] = ['opportunities' => DB::table('opportunities')->count(),
|
|
'documents' => DB::table('documents')->count(), 'library_resources' => DB::table('portal_resources')->count()];
|
|
file_put_contents($private.'/legacy-persistence-qa.json', json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|