Files
Investidor-V2/tools/portal-dashboard-qa-snapshot.php
nala 01405cbf8a
tests / ci (push) Canceled after 0s
oportunidades 5
2026-10-10 14:15:28 +02:00

40 lines
2.1 KiB
PHP

<?php
use App\Models\Opportunity;
use App\Models\User;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
require dirname(__DIR__).'/vendor/autoload.php';
require __DIR__.'/portal-qa-environment.php';
$target = portalQaEnvironment();
$app = require dirname(__DIR__).'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
portalQaAssertTarget($target);
config(['portal.managers' => ['opportunity-manager@example.invalid', 'geo-manager-qa@example.invalid']]);
$db = DB::connection();
$db->beginTransaction();
$db->statement('SET TRANSACTION READ ONLY');
try {
$proof = ['target' => $target, 'tables' => [], 'opportunities' => [], 'accounts' => [], 'active_writes' => 0];
foreach (['opportunity_projects', 'opportunity_clusters', 'opportunity_images', 'opportunity_documents', 'opportunity_locations', 'documents', 'desk_cases', 'desk_requests', 'desk_documents', 'investor_journeys', 'journey_steps', 'tasks', 'questionnaire_versions', 'geo_locations', 'geo_geometries'] as $table) {
if (! Schema::hasTable($table)) {
continue;
}
$rows = $db->select('SELECT row_to_json(t)::text AS row FROM "'.$table.'" t ORDER BY row_to_json(t)::text');
$proof['tables'][$table] = ['rows' => count($rows), 'sha256' => hash('sha256', implode("\n", array_column($rows, 'row')))];
}
foreach ($db->select('SELECT id,row_to_json(t)::text AS row FROM opportunities t ORDER BY id') as $row) {
$proof['opportunities'][$row->id] = hash('sha256', $row->row);
}
$proof['published'] = Opportunity::published()->count();
foreach (User::whereIn('email', config('portal.managers'))->orWhereIn('id', [13, 18])->get() as $user) {
$proof['accounts'][] = ['id' => $user->id, 'manage_portal' => $user->can('manage-portal'), 'email_verified' => $user->hasVerifiedEmail(), 'mfa_configured' => (bool) $user->two_factor_secret];
}
$proof['account18_sha256'] = hash('sha256', json_encode($db->table('users')->where('id', 18)->first(), JSON_THROW_ON_ERROR));
} finally {
$db->rollBack();
}
echo json_encode($proof, JSON_THROW_ON_ERROR).PHP_EOL;