versao nrgocios 3
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-18 11:17:35 +02:00
parent cef6e201c7
commit 6bc0cc6f52
18199 changed files with 3919254 additions and 10257 deletions
@@ -42,12 +42,14 @@ class InvestmentZoneOperationalProfile
$draft = $this->draft($zone);
return [...$zone->toArray(), ...($draft['fields'] ?? []), 'version_no'=>$draft['working_version'] ?? $zone->version_no,
'public_version_no'=>$zone->version_no, 'base_public_version'=>$draft['base_public_version'] ?? $zone->version_no,
'has_private_draft'=>$draft !== null, 'profile_available'=>$this->installed()];
'has_private_draft'=>$draft !== null, 'profile_available'=>$this->installed(),
'operational_details'=>($draft['fields']['operational_details'] ?? app(InvestmentZoneOperationalDetails::class)->recover($zone)),
'details_available'=>app(InvestmentZoneOperationalDetails::class)->installed()];
}
public function publicDetails(array $record): array
{
unset($record['editorial_draft']);
unset($record['editorial_draft'], $record['operational_details']);
foreach (['activities','resources'] as $key) {
if (isset($record[$key])) { $record[$key] = array_map(fn ($item)=>array_intersect_key($item,array_flip(self::DETAIL_PUBLIC)), $record[$key]); }
}
@@ -83,11 +85,23 @@ class InvestmentZoneOperationalProfile
$previous=$this->draft($zone);
$base=$previous['fields'] ?? array_intersect_key($zone->toArray(),array_flip(self::FIELDS));
$fields=[...$base,...array_intersect_key($data,array_flip(self::FIELDS))];
$details=app(InvestmentZoneOperationalDetails::class);
if (array_key_exists('operational_details',$data)) {
$fields['operational_details']=$details->merge($zone,$base['operational_details'] ?? $details->recover($zone),$data['operational_details'],$fields['operator_id'] ?? null);
} elseif ($details->stored($zone) && !array_key_exists('operational_details',$fields)) {
$fields['operational_details']=$details->recover($zone);
}
$details=app(InvestmentZoneOperationalDetails::class);
if (array_key_exists('operational_details',$data)) {
$fields['operational_details']=$details->merge($zone,$base['operational_details'] ?? $details->recover($zone),$data['operational_details'],$fields['operator_id'] ?? null);
} elseif ($details->stored($zone) && !array_key_exists('operational_details',$fields)) {
$fields['operational_details']=$details->recover($zone);
}
foreach (['activities','resources'] as $key) { if (array_key_exists($key,$data)) { $fields[$key]=$this->mergeDetails($zone->id,$base[$key] ?? [],$data[$key]); } }
$draft=['schema_version'=>1,'base_public_version'=>$previous['base_public_version'] ?? (int)$zone->version_no,
'working_version'=>$this->nextVersion($zone),'fields'=>$fields,'actor_id'=>$actor,'prepared_at'=>now()->toIso8601String()];
DB::table('investment_zones')->where('id',$zone->id)->update(['editorial_draft'=>Crypt::encryptString(json_encode($draft,JSON_THROW_ON_ERROR))]);
$this->snapshot($zone,$draft['working_version'],$actor,'profile_prepared',['public'=>$zone->toArray(),'draft'=>$draft]);
$this->snapshot($zone,$draft['working_version'],$actor,'profile_prepared',['public'=>[...$zone->toArray(),'operational_details'=>$details->stored($zone)],'draft'=>$draft]);
return $zone->fresh();
}
@@ -99,7 +113,10 @@ class InvestmentZoneOperationalProfile
if (!$draft) { return; }
abort_unless((int)$draft['base_public_version']===(int)$zone->version_no,409,'A publicação base mudou. Reconcilie a preparação antes de publicar; ambos os estados foram preservados.');
$zone->fill(array_intersect_key($draft['fields'],array_flip(self::FIELDS)));
// Support identifiers and private notes stay in the encrypted immutable preparation snapshot.
if (array_key_exists('operational_details',$draft['fields'])) {
$zone->setAttribute('operational_details',app(InvestmentZoneOperationalDetails::class)->pack($draft['fields']['operational_details']));
}
// Existing resource support remains in the encrypted snapshot; L1 private fields are durable.
foreach(['activities','resources'] as $key) { $zone->setAttribute($key,$this->publicDetails([$key=>$zone->$key ?? []])[$key]); }
$zone->setAttribute('editorial_draft',null);
}
@@ -111,7 +128,7 @@ class InvestmentZoneOperationalProfile
abort_if((int)$draft['base_public_version']===$public,422,'A preparação já corresponde à versão pública atual.');
$draft['base_public_version']=$public;$draft['working_version']=$this->nextVersion($zone);$draft['actor_id']=$actor;$draft['prepared_at']=now()->toIso8601String();
DB::table('investment_zones')->where('id',$zone->id)->update(['editorial_draft'=>Crypt::encryptString(json_encode($draft,JSON_THROW_ON_ERROR))]);
$this->snapshot($zone,$draft['working_version'],$actor,'profile_reconciled',['public'=>$zone->toArray(),'draft'=>$draft]);
$this->snapshot($zone,$draft['working_version'],$actor,'profile_reconciled',['public'=>[...$zone->toArray(),'operational_details'=>app(InvestmentZoneOperationalDetails::class)->stored($zone)],'draft'=>$draft]);
return $zone->fresh();
}