Files
compras/scripts/prepare-sgf-operational.php
T
2026-11-02 08:08:05 +02:00

48 lines
2.4 KiB
PHP

<?php
use Tempo\Purchasing\Delivery\AccessOverlay;
use Tempo\Purchasing\Delivery\BootOverlay;
use Tempo\Purchasing\Delivery\BudgetOverlay;
require dirname(__DIR__).'/integrations/sgf/access/AccessOverlay.php';
require dirname(__DIR__).'/integrations/sgf/operational/BudgetOverlay.php';
require dirname(__DIR__).'/integrations/sgf/operational/BootOverlay.php';
$host = realpath($argv[1] ?? dirname(__DIR__).'/../sgf-tempo');
if (! $host) {
throw new RuntimeException('Host inexistente.');
}
$files = AccessOverlay::prepare($host) + BudgetOverlay::prepare($host) + BootOverlay::prepare($host);
$root = dirname(__DIR__);
$support = [];
foreach (['integrations/sgf/operational', 'integrations/sgf/access', 'integrations/sgf/internal-requisitions', 'packages/purchasing/src'] as $directory) {
foreach (new DirectoryIterator($root.'/'.$directory) as $file) {
if ($file->isFile() && ! $file->isLink()) {
$support[$directory.'/'.$file->getFilename()] = file_get_contents($file->getPathname());
}
}
}
ksort($support);
$support['scripts/sgf-internal-install.php'] = file_get_contents($root.'/scripts/sgf-internal-install.php');
$support['bootstrap.php'] = file_get_contents($root.'/integrations/sgf/operational/entry.php');
$hash = hash('sha256', json_encode([$files, $support], JSON_THROW_ON_ERROR));
$directory = $root.'/storage/app/private/candidates/OPERATIONAL-CANDIDATE-'.substr($hash, 0, 16);
$manifest = ['format' => 'tempo.operational-review.v1', 'installed' => false, 'activated' => false, 'host_version_preserved' => '0.1.1', 'host_overlays' => [], 'support_files' => []];
foreach ($files as $path => $file) {
$support[$path] = $file['contents'];
unset($file['contents']);
$manifest['host_overlays'][$path] = $file;
}
foreach ($support as $path => $contents) {
$target = $directory.'/'.$path;
if (! is_dir(dirname($target))) {
mkdir(dirname($target), 0700, true);
}
if (is_file($target) && hash_file('sha256', $target) !== hash('sha256', $contents)) {
throw new RuntimeException('Candidata imutável divergente.');
}
file_put_contents($target, $contents);
$manifest['support_files'][$path] = hash('sha256', $contents);
}
file_put_contents($directory.'/manifest.json', json_encode($manifest, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
echo json_encode(['directory' => $directory, 'installed' => false], JSON_THROW_ON_ERROR)."\n";