commit14
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Tempo\Purchasing\Delivery;
|
||||
|
||||
/** Native administration consumes the server catalogue; no second authority list. */
|
||||
final class AdminUiOverlay
|
||||
{
|
||||
public static function prepare(string $host, array $files): array
|
||||
{
|
||||
$workflow = 'app/Modules/Identity/Services/IdentityWorkflow.php';
|
||||
$old = "'catalogue' => ['company' => Permissions::COMPANY, 'unit' => Permissions::UNIT]];";
|
||||
$contents = $files[$workflow]['contents'];
|
||||
if (substr_count($contents, $old) !== 1) {
|
||||
throw new \RuntimeException('Catálogo administrativo do host divergiu.');
|
||||
}
|
||||
$contents = str_replace($old, "'catalogue' => ['company' => Permissions::COMPANY, 'unit' => Permissions::UNIT], 'catalogue_labels' => \\Tempo\\Purchasing\\Delivery\\AccessOverlay::LABELS];", $contents);
|
||||
$files[$workflow]['contents'] = $contents;
|
||||
$files[$workflow]['after_sha256'] = hash('sha256', $contents);
|
||||
$node = getenv('SGF_NODE_BINARY') ?: 'node';
|
||||
$process = proc_open([$node, dirname(__DIR__, 3).'/scripts/sgf-admin-ui-build.mjs', $host], [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
|
||||
if (! is_resource($process)) {
|
||||
throw new \RuntimeException('Não foi possível preparar a interface.');
|
||||
}
|
||||
fclose($pipes[0]);
|
||||
$output = stream_get_contents($pipes[1]);
|
||||
$error = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
if (proc_close($process) !== 0) {
|
||||
throw new \RuntimeException('Frontend candidato: '.$error);
|
||||
}
|
||||
$metadata = json_decode(file_get_contents(json_decode($output, true, 16, JSON_THROW_ON_ERROR)['metadata']), true, 32, JSON_THROW_ON_ERROR);
|
||||
foreach ($metadata['overlays'] as $file => $source) {
|
||||
$body = file_get_contents($source);
|
||||
$files[$file] = ['before_sha256' => hash_file('sha256', $host.'/'.$file), 'after_sha256' => hash('sha256', $body), 'contents' => $body];
|
||||
}
|
||||
$assets = [];
|
||||
foreach ($metadata['assets'] as $file => $source) {
|
||||
$assets[$file] = file_get_contents($source);
|
||||
}
|
||||
|
||||
return ['files' => $files, 'assets' => $assets];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user