58 lines
4.9 KiB
PHP
58 lines
4.9 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');
|
|
putenv('STABILITY_QA_MODE=consumers');
|
|
$tasksRoot=dirname(__DIR__,2);
|
|
$tasksQA=$tasksRoot.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
|
|
$proofPath=__DIR__.'/case32-current-tasks-readonly-20261014.json';
|
|
if(is_file($proofPath)){throw new RuntimeException('Preservar prova existente.');}
|
|
$app=require $tasksQA.'/tools/portal-stability-runtime.php';
|
|
$db=Illuminate\Support\Facades\DB::connection();
|
|
$target=(array)$db->selectOne('SELECT current_database() AS database,inet_server_port() AS port');
|
|
if($target!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441]){throw new RuntimeException('QA isolada obrigatória.');}
|
|
$db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY');
|
|
try{
|
|
$record=App\Models\Opportunity::findOrFail(32);
|
|
$access=app(App\Services\PortalProfileAccess::class);
|
|
$context=$record->workflow_context??[];
|
|
$cycle=(int)($context['review_cycle']??0);
|
|
$rows=$db->table('tasks')->where('source_system','opportunity-workflow')->where('external_id','like','portal-opportunity:32:%')
|
|
->orderBy('created_at')->get(['id','external_id','task_type','status','assignee_user_id','due_at','completed_at','created_at']);
|
|
$tasks=[];$counts=[];$keys=[];
|
|
foreach($rows as $row){
|
|
$key=$row->external_id;$keys[$key]=($keys[$key]??0)+1;
|
|
$counts[$row->status]=($counts[$row->status]??0)+1;
|
|
$rowCycle=preg_match('/:cycle:(\d+)$/D',$key,$m)?(int)$m[1]:null;
|
|
$tasks[]=['id'=>$row->id,'type'=>$row->task_type,'state'=>$row->status,'QA_assignee'=>$row->assignee_user_id,
|
|
'cycle'=>$rowCycle,'belongs_to_current_cycle'=>$rowCycle===$cycle,'due_at'=>$row->due_at,'completed_at'=>$row->completed_at];
|
|
}
|
|
$submits=array_values(array_filter($context['events']??[],fn($e)=>($e['action']??'')==='submit'&&(int)($e['review_cycle']??0)===$cycle));
|
|
$cutoff=$submits!==[]?new DateTimeImmutable($submits[count($submits)-1]['at']):null;
|
|
$corrections=array_values(array_filter($context['events']??[],fn($e)=>($e['action']??'')==='request_correction'
|
|
&&(int)($e['review_cycle']??0)===$cycle&&$cutoff!==null&&new DateTimeImmutable($e['at'])>=$cutoff));
|
|
$event=$corrections!==[]?$corrections[count($corrections)-1]:null;
|
|
$audit=$db->table('audit_events')->where('source_system','portal-profiles-v1')->where('action','workflow_request_correction')
|
|
->whereRaw("after_data->>'record_id'=?",['32'])->orderByDesc('created_at')->first(['id','created_at','after_data']);
|
|
$auditData=$audit?json_decode($audit->after_data,true,512,JSON_THROW_ON_ERROR):[];
|
|
$matched=$event!==null&&$audit!==null&&($auditData['after']['status']??'')===($event['to']??'')&&new DateTimeImmutable($audit->created_at)>=$cutoff;
|
|
$receipt=['at'=>gmdate('c'),'base_review'=>'396c691930bc','target'=>$target,'SQL_read_only'=>true,'opportunity_id'=>32,
|
|
'manual_observation'=>'Lista de tarefas com anteriores done e uma correção open; SLA sem política/prazo aprovado.',
|
|
'working_state'=>$access->state($record),'management_version'=>(int)$record->management_version,
|
|
'review_cycle'=>$cycle,'content_revision'=>$context['content_revision']??null,
|
|
'counts'=>$counts,'tasks'=>$tasks,'duplicate_external_keys'=>array_keys(array_filter($keys,fn($count)=>$count>1)),
|
|
'current_correction_task_id'=>$context['correction_task_id']??null,
|
|
'request_correction_current_cycle_audited'=>$matched,
|
|
'request_correction_event'=>$event?array_intersect_key($event,array_flip(['action','actor_id','at','from','to','review_cycle','content_revision'])):null,
|
|
'request_correction_audit_id'=>$matched?$audit->id:null,
|
|
'QA21_can_view'=>$access->canView(App\Models\User::findOrFail(21),$record),
|
|
'QA21_can_edit'=>$access->canEdit(App\Models\User::findOrFail(21),$record),
|
|
'SLA'=>array_intersect_key($context['sla']??[],array_flip(['policy_version','due_at','status'])),
|
|
'presentation_limitation'=>'Listing emits historical tasks without cycle/version labels; identical titles do not alone prove duplicate records.',
|
|
'limits'=>['No task assignment, workflow transition or scheduling performed.','No task outcome, correction text, IP, session or secret exported.'],
|
|
'QA_database_changes'=>0,'active_changes'=>0];
|
|
file_put_contents($proofPath,json_encode($receipt,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
|
|
echo json_encode(['state'=>$receipt['working_state'],'cycle'=>$cycle,'version'=>$receipt['management_version'],
|
|
'counts'=>$counts,'duplicates'=>count($receipt['duplicate_external_keys']),'current_correction_audited'=>$matched,
|
|
'QA21_can_edit'=>$receipt['QA21_can_edit'],'open_tasks'=>array_values(array_filter($tasks,fn($t)=>in_array($t['state'],['open','in_progress'],true))),
|
|
'active_changes'=>0],JSON_THROW_ON_ERROR).PHP_EOL;
|
|
}finally{$db->rollBack();}
|