25 lines
3.3 KiB
PHP
25 lines
3.3 KiB
PHP
<?php
|
|
$root=dirname(__DIR__);
|
|
$old=json_decode(file_get_contents($root.'/docs/proofs/sgf-read-candidate.json'),true,32,JSON_THROW_ON_ERROR);
|
|
$manifest=json_decode(file_get_contents($old['directory'].'/manifest.json'),true,64,JSON_THROW_ON_ERROR);
|
|
$payload=[];
|
|
foreach($manifest['support_files'] as $file=>$hash){$text=file_get_contents($old['directory'].'/'.$file);if(hash('sha256',$text)!==$hash)throw new RuntimeException('Prior candidate changed');$payload[$file]=$text;}
|
|
foreach(['integrations/sgf/sourcing','packages/purchasing/src'] as $dir)foreach(new DirectoryIterator($root.'/'.$dir) as $file)if($file->isFile())$payload[$dir.'/'.$file->getFilename()]=file_get_contents($file->getPathname());
|
|
foreach(['integrations/sgf/operational/Installation.php','integrations/sgf/operational/CodeDeployment.php','integrations/sgf/access/AccessOverlay.php','integrations/sgf/operational/routes.php','integrations/sgf/internal-requisitions/Controller.php','integrations/sgf/internal-requisitions/screen.mjs'] as $file)$payload[$file]=file_get_contents($root.'/'.$file);
|
|
$payload['bootstrap.php']=file_get_contents($root.'/integrations/sgf/operational/entry.php');
|
|
$payload['scripts/sgf-sourcing-install.php']=file_get_contents($root.'/scripts/sgf-sourcing-install.php');
|
|
require_once $root.'/app/Services/ComparisonPolicy.php';
|
|
$payload['integrations/sgf/sourcing/comparison-defaults.json']=json_encode(App\Services\ComparisonPolicy::DEFAULTS,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);
|
|
$file='app/Modules/Identity/Services/Permissions.php';
|
|
$payload[$file]=preg_replace('/public const UNIT = .*?;/s','public const UNIT = '.var_export(['unit.view','unit.edit',...requireRights($root)],true).';',$payload[$file],1);
|
|
$manifest['host_overlays'][$file]['after_sha256']=hash('sha256',$payload[$file]);
|
|
// The same native catalogue and delegation workflow remain in use.
|
|
foreach($payload as $file=>$text)$manifest['support_files'][$file]=hash('sha256',$text);
|
|
$manifestText=json_encode($manifest,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);
|
|
$id='OPERATIONAL-CANDIDATE-'.substr(hash('sha256',$manifestText),0,16);$dir=$root.'/storage/app/private/candidates/'.$id;
|
|
if(file_exists($dir))throw new RuntimeException('Immutable candidate exists');mkdir($dir,0700,true);
|
|
foreach($payload+['manifest.json'=>$manifestText] as $file=>$text){if(!is_dir(dirname($dir.'/'.$file)))mkdir(dirname($dir.'/'.$file),0700,true);file_put_contents($dir.'/'.$file,$text);}
|
|
$archive=$root.'/storage/app/private/candidate-archives/'.$id.'.zip';$zip=new ZipArchive;if($zip->open($archive,ZipArchive::CREATE|ZipArchive::EXCL)!==true)throw new RuntimeException('Archive exists');foreach([...array_keys($payload),'manifest.json'] as $file)$zip->addFile($dir.'/'.$file,$file);$zip->close();
|
|
$out=['directory'=>$dir,'archive'=>['file'=>$archive,'sha256'=>hash_file('sha256',$archive),'manifest_sha256'=>hash('sha256',$manifestText)],'prior_manifest_sha256'=>$old['archive']['manifest_sha256'],'schema_extension'=>'sourcing revision 1; four ss_* tables and explicit catalogue extension','real_activated'=>false];file_put_contents($root.'/docs/proofs/sgf-sourcing-candidate.json',json_encode($out,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($out,JSON_PRETTY_PRINT);
|
|
function requireRights(string $root):array{require_once $root.'/integrations/sgf/access/AccessOverlay.php';return Tempo\Purchasing\Delivery\AccessOverlay::RIGHTS;}
|