Files
Investidor-V2/outputs/investmoz-audit-current-20261012/verify-case32-task-history-readonly-20261014.php
T
nala 5738418838
tests / ci (push) Canceled after 0s
oportunidades 9
2026-10-14 16:57:56 +02:00

47 lines
3.6 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');
putenv('STABILITY_QA_MODE=consumers');
$taskRoot=dirname(__DIR__,2);
$taskQA=$taskRoot.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
$proofPath=__DIR__.'/case32-task-history-readonly-20261014.json';
if(is_file($proofPath)){throw new RuntimeException('Preservar prova anterior.');}
$app=require $taskQA.'/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);$context=$record->workflow_context??[];
$rows=$db->table('tasks')->where('source_system','opportunity-workflow')->where('external_id','like','portal-opportunity:32:%')
->get(['id','external_id','task_type','status','assignee_user_id','due_at']);
$groups=[];$keys=[];$bindings=[];
foreach(['review_task_id','publication_task_id','correction_task_id']as$key){if(!empty($context[$key])){$bindings[$context[$key]]=$key;}}
$bound=[];
foreach($rows as$row){
$keys[$row->external_id]=($keys[$row->external_id]??0)+1;
$match=[];$cycle=preg_match('/:cycle:(\d+)$/D',$row->external_id,$match)?(int)$match[1]:null;
$bucket=$cycle===null?'legacy_without_cycle':(string)$cycle;
$groupKey=$bucket.':'.$row->task_type;
$groups[$groupKey]??=['review_cycle'=>$cycle,'task_type'=>$row->task_type,'count'=>0,'statuses'=>[]];
$groups[$groupKey]['count']++;
$groups[$groupKey]['statuses'][$row->status]=($groups[$groupKey]['statuses'][$row->status]??0)+1;
if(isset($bindings[$row->id])){$bound[]=['binding'=>$bindings[$row->id],'review_cycle'=>$cycle,
'task_type'=>$row->task_type,'status'=>$row->status,'assignee_user_id'=>$row->assignee_user_id,'due_at'=>$row->due_at];}
}
$duplicateKeys=array_filter($keys,fn($count)=>$count>1);
$proof=['at'=>gmdate('c'),'base_review'=>'396c691930bc','target'=>$target,'SQL_read_only'=>true,'case'=>32,
'working_state'=>app(App\Services\PortalProfileAccess::class)->state($record),'version'=>(int)$record->management_version,
'review_cycle'=>$context['review_cycle'],'content_revision'=>$context['content_revision'],
'total_task_rows'=>$rows->count(),'distinct_task_IDs'=>$rows->pluck('id')->unique()->count(),
'distinct_task_keys'=>count($keys),'duplicate_task_key_groups'=>count($duplicateKeys),
'groups_by_cycle_and_type'=>array_values($groups),'current_context_bindings'=>$bound,
'UI_lists_all_cycles_without_labels'=>true,'UI_source'=>'OpportunityWorkflowTasks::listing + opportunity-draft.tsx',
'historical_tasks_preserved'=>true,'task_titles_reasons_private_content_not_exported'=>true,
'QA_database_changes'=>0,'active_changes'=>0];
file_put_contents($proofPath,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL);
echo json_encode(['state'=>$proof['working_state'],'version'=>$proof['version'],'review_cycle'=>$proof['review_cycle'],
'total_tasks'=>$proof['total_task_rows'],'distinct_keys'=>$proof['distinct_task_keys'],
'duplicate_key_groups'=>$proof['duplicate_task_key_groups'],'groups'=>$proof['groups_by_cycle_and_type'],
'bound_tasks'=>$bound,'active_changes'=>0],JSON_THROW_ON_ERROR).PHP_EOL;
}finally{$db->rollBack();}