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();}