42 lines
4.2 KiB
PHP
42 lines
4.2 KiB
PHP
<?php
|
|
// Demonstration preparation only; no product implementation or active connection.
|
|
ini_set('zend.exception_ignore_args', '1');
|
|
try {
|
|
$portal = dirname(__DIR__, 2);
|
|
$plan = json_decode(file_get_contents($portal.'/storage/app/private/investmoz-v2/portal-audit/internal-designation-plan.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$qa = $plan['source'];
|
|
if (!str_contains($qa, '/onboarding-qa-internal-') && !str_contains($qa, '\\onboarding-qa-internal-')) throw new RuntimeException('Separate QA tree required');
|
|
require $qa.'/qa-autoload.php';
|
|
$app = require $qa.'/bootstrap/app.php';
|
|
(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);
|
|
(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
|
|
$c = config('database.connections.'.config('database.default'));
|
|
if ($c['driver'] !== 'pgsql' || (int)$c['port'] !== 55441 || $c['database'] !== 'onboarding_internal_20261011_191450_test' || !empty($c['url']) || !in_array($c['host'], ['127.0.0.1','localhost'], true)) throw new RuntimeException('QA configuration mismatch');
|
|
$db = new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$c['database'], $c['username'], $c['password'], [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
|
|
$db->exec('BEGIN READ ONLY');
|
|
if ((int)$db->query('SELECT inet_server_port()')->fetchColumn() !== 55441) throw new RuntimeException('Actual server mismatch');
|
|
$actors = json_decode(file_get_contents($qa.'/storage/app/private/onboarding-actors-local.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$accounts = [];
|
|
$key = config('app.key');
|
|
if (str_starts_with($key, 'base64:')) $key = base64_decode(substr($key, 7));
|
|
$encrypter = new Illuminate\Encryption\Encrypter($key, config('app.cipher'));
|
|
foreach ($actors as $role=>$a) {
|
|
$s = $db->prepare('SELECT id,email,password,email_verified_at,two_factor_secret,two_factor_confirmed_at FROM users WHERE id=?');
|
|
$s->execute([$a['id']]); $u = $s->fetch(PDO::FETCH_ASSOC);
|
|
$readable = false;
|
|
if (!empty($u['two_factor_secret'])) { $encrypter->decrypt($u['two_factor_secret']); $readable = true; }
|
|
$accounts[$role] = ['id'=>$u['id'], 'email'=>$u['email'], 'password_matches'=>password_verify($a['password'],$u['password']), 'contact_verified'=>!empty($u['email_verified_at']), 'MFA_confirmed'=>!empty($u['two_factor_confirmed_at']), 'MFA_readable'=>$readable];
|
|
}
|
|
$counts = [];
|
|
foreach (['opportunities','documents','contacts','economic_activities','geo_locations','jobs','failed_jobs'] as $table) $counts[$table] = (int)$db->query('SELECT count(*) FROM '.$table)->fetchColumn();
|
|
$grants = $db->query('SELECT user_id,role,organization_id,opportunity_types,responsibilities,revoked_at FROM portal_role_assignments')->fetchAll(PDO::FETCH_ASSOC);
|
|
$records = $db->query('SELECT id,title,status,owner_user_id,organization_id FROM opportunities WHERE owner_user_id IS NOT NULL ORDER BY id')->fetchAll(PDO::FETCH_ASSOC);
|
|
$jobs = $db->query('SELECT id,queue,payload FROM jobs')->fetchAll(PDO::FETCH_ASSOC);
|
|
$jobKinds = array_map(fn($j)=>['id'=>$j['id'],'queue'=>$j['queue'],'class'=>json_decode($j['payload'],true)['displayName']??'unknown'], $jobs);
|
|
$refs = ['organizations'=>$db->query('SELECT id,name,source_system FROM organizations')->fetchAll(PDO::FETCH_ASSOC), 'contacts'=>$db->query('SELECT id,full_name FROM contacts WHERE deleted_at IS NULL LIMIT 5')->fetchAll(PDO::FETCH_ASSOC), 'economic_activities'=>$db->query('SELECT id,parent_id,sector_id,label_pt_mz FROM economic_activities WHERE status=\'published\' LIMIT 8')->fetchAll(PDO::FETCH_ASSOC)];
|
|
$db->exec('ROLLBACK');
|
|
echo json_encode(['result'=>'read_only_QA_verified','target'=>$plan['target'], 'source'=>$qa,'actors'=>$accounts,'counts'=>$counts,'grants'=>$grants,'records'=>$records,'jobs'=>$jobKinds,'references'=>$refs,'config'=>['APP_URL'=>config('app.url'),'cookie'=>config('session.cookie'),'queue'=>config('queue.default'),'scanner'=>config('services.malware.scanner'),'workflow'=>config('portal.profile_access_enabled'),'notifications'=>config('portal.notifications_enabled')]],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);
|
|
} catch (Throwable $e) {
|
|
echo json_encode(['result'=>'stopped','exception'=>$e::class,'line'=>$e->getLine()],JSON_THROW_ON_ERROR);exit(1);
|
|
}
|