Files
SGF/scripts/sgf-install-hr-personnel.php
2026-11-11 15:04:01 +02:00

10 lines
4.8 KiB
PHP

<?php
$book='8085';require __DIR__.'/sgf-single-bootstrap.php';
foreach([$s['root'].'/hp-ui-20261111.json',$run['root'].'/private/receipt-composition-b4093c6f6707/single-integration/20261111-085805-d6985581/hp-result.json',$run['root'].'/private/receipt-composition-b4093c6f6707/single-integration/20261111-085910-105a205c/hp-boundaries.json',$run['root'].'/private/receipt-composition-b4093c6f6707/single-integration/20261111-090216-f627a6b2/hp-privacy.json',$run['root'].'/private/receipt-composition-b4093c6f6707/hp-concurrency-1794380380400/result.json']as$file)if((json_decode(file_get_contents($file),true)['passed']??false)!==true)throw new LogicException('Affected proofs required');
$previous=json_decode(file_get_contents($s['root'].'/single-integration/20261111-073116-5f71ef3d/statements-installation.json'),true);$qualified=array_merge($previous['identical_original_tables'],['host.rm_meta','host.rm_versions','host.rm_commands','host.hr_qa_profiles','host.users','host.company_memberships','host.sgf_presentation_profiles','host.hp_meta','host.hp_versions','host.hp_commands']);$before=[];$order=fn($table)=>in_array($table,['sr_outbox','sr_deliveries'],true)?'event_id':(in_array($table,['sc_catalogue_meta','pd_due_meta','fo_meta','fs_meta','rm_meta','hp_meta'],true)?'policy':(in_array($table,['hr_qa_profiles','sgf_presentation_profiles'],true)?'profile_key':(in_array($table,['fs_results','fs_result_lines'],true)?'snapshot_key':($table==='company_memberships'?'user_id':'id'))));foreach($qualified as$key){[$name,$table]=explode('.',$key);$db=$name==='host'?$host:$native;$before[$name][$table]=$db->table($table)->orderBy($order($table))->when($table==='fs_result_lines',fn($q)=>$q->orderBy('account_id'))->get()->toJson();}$binding=hash_file('sha256',$s['root'].'/binding.json');file_put_contents($work.'/preservation-private.json',json_encode($before));
$files=['routes/web.php', 'app/Modules/HumanResources/Personnel.php', 'app/Modules/HumanResources/PersonnelTime.php', 'app/Modules/HumanResources/Remunerations.php', 'app/Modules/HumanResources/Http/PersonnelController.php', 'app/Shared/Installation/PresentationEntry.php','app/Shared/Context/ModuleNavigation.php', 'app/Modules/Identity/Services/IdentityWorkflow.php', 'resources/js/workspace-overview.js','resources/js/PersonnelWorkspace.jsx', 'resources/js/RemunerationsWorkspace.jsx', 'resources/js/app.jsx', 'resources/js/WorkspaceNavigation.jsx', 'resources/js/statement-download.js', 'database/sql/hr_personnel.sql', 'docs/integration/sgf-human-resources-personnel-access-proposal.json'];foreach($files as$file)if(str_ends_with($file,'.php'))(new Symfony\Component\Process\Process([PHP_BINARY,'-l',$repo.'/'.$file]))->mustRun();$hashes=[];$copy=function($src,$file)use($s,$work,&$hashes){$dest=$s['app'].'/'.$file;$backup=$work.'/before/'.$file;if(is_file($dest)){if(!is_dir(dirname($backup)))mkdir(dirname($backup),0700,true);copy($dest,$backup);}if(!is_dir(dirname($dest)))mkdir(dirname($dest),0700,true);copy($src,$dest);$hashes[$file]=hash_file('sha256',$dest);};foreach($files as$file)$copy($repo.'/'.$file,$file);
$a=json_decode(file_get_contents($repo.'/docs/integration/sgf-human-resources-personnel-access-proposal.json'),true);$cfg=['enabled'=>true,'schema_sha256'=>hash_file('sha256',$repo.'/database/sql/hr_personnel.sql'),'access_sha256'=>hash('sha256',Tempo\Finance\Payables\Payables::canonical(['scope'=>$a['scope'],'grants'=>$a['grants_per_book']]))];$file=$work.'/hr_personnel.php';file_put_contents($file,"<?php\nreturn ".var_export($cfg,true).";\n");$copy($file,'config/hr_personnel.php');
$build=$run['root'].'/private/single-hr-personnel-final-build-20261111';$manifest=json_decode(file_get_contents($build.'/manifest.json'),true);$assets=[];foreach($manifest as$entry){$assets[]=$entry['file'];foreach($entry['css']??[]as$file)$assets[]=$file;}foreach(array_unique($assets)as$file){if(!preg_match('~^assets/[a-zA-Z0-9_.-]+$~D',$file))throw new LogicException('Asset path invalid');$copy($build.'/'.$file,'public/build/'.$file);}$copy($build.'/manifest.json','public/build/manifest.json');
$checks=[];foreach($before as$name=>$tables){$db=$name==='host'?$host:$native;foreach($tables as$table=>$json){if($db->table($table)->orderBy($order($table))->when($table==='fs_result_lines',fn($q)=>$q->orderBy('account_id'))->get()->toJson()!==$json)throw new LogicException('Original facts changed '.$table);$checks[]=$name.'.'.$table;}}if($binding!==hash_file('sha256',$s['root'].'/binding.json'))throw new LogicException('Binding changed');file_put_contents($work.'/hp-installation.json',json_encode(['passed'=>true,'hashes'=>$hashes,'identical_original_tables'=>$checks,'business_commands'=>0,'new_grants'=>0,'new_demo'=>false,'cache_cleared'=>false,'native_writes'=>0,'binding_unchanged'=>true],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'proof'=>$work.'/hp-installation.json']).PHP_EOL;