55 lines
3.7 KiB
PHP
55 lines
3.7 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
$root = dirname(__DIR__);
|
|
$settings = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json'), true, 32, JSON_THROW_ON_ERROR);
|
|
if (($settings['APP_ENV'] ?? '') !== 'payable-testing' || ($settings['DB_HOST'] ?? '') !== '127.0.0.1' || realpath($settings['HOST_ROOT'] ?? '') !== realpath($root)
|
|
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $settings['DB_DATABASE'] ?? '', $matches) || $settings['DB_USERNAME'] !== 'payable_qa_'.$matches[1]) {
|
|
throw new LogicException('Wrong pilot destination.');
|
|
}
|
|
|
|
if (! in_array('--apply-authorized', $argv ?? [], true)) {
|
|
throw new LogicException('Explicit activation flag required.');
|
|
}
|
|
$authorization = json_decode(file_get_contents($root.'/docs/proofs/administrative-geography-installation-authorization.json'), true, 32, JSON_THROW_ON_ERROR);
|
|
$installation = json_decode(file_get_contents($root.'/docs/proofs/administrative-geography-installation.json'), true, 32, JSON_THROW_ON_ERROR);
|
|
$settingsFile = 'C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json';
|
|
$before = file_get_contents($settingsFile);
|
|
if ($authorization['scope'] !== 'install_two_nullable_geography_columns_and_enable_selection' || $installation['result'] !== 'passed'
|
|
|| ! $installation['new_references_all_null'] || ! $installation['restore_database_removed']
|
|
|| filter_var($settings['SGC_TWO_FACTOR_ENABLED'] ?? false, FILTER_VALIDATE_BOOLEAN)
|
|
|| filter_var($settings['SGC_GEOGRAPHY_ENABLED'] ?? false, FILTER_VALIDATE_BOOLEAN)
|
|
|| file_exists($root.'/docs/proofs/administrative-geography-activation.json')) {
|
|
throw new LogicException('Activation authorization or current state differs.');
|
|
}
|
|
$after = [...$settings, 'SGC_GEOGRAPHY_ENABLED' => 'true'];
|
|
$protectedBefore = $settings;
|
|
$protectedAfter = $after;
|
|
unset($protectedBefore['SGC_GEOGRAPHY_ENABLED'], $protectedAfter['SGC_GEOGRAPHY_ENABLED']);
|
|
if ($protectedBefore !== $protectedAfter) {
|
|
throw new LogicException('Unrelated setting change.');
|
|
}
|
|
$backup = dirname($installation['backup']).'/settings-before.json';
|
|
if (file_put_contents($backup, $before, LOCK_EX) !== strlen($before)) {
|
|
throw new RuntimeException('Settings backup failed.');
|
|
}
|
|
$encoded = json_encode($after, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR).PHP_EOL;
|
|
$temporary = $settingsFile.'.geography-'.bin2hex(random_bytes(4)).'.tmp';
|
|
if (file_put_contents($temporary, $encoded, LOCK_EX) !== strlen($encoded)) {
|
|
throw new RuntimeException('Settings preparation failed.');
|
|
}
|
|
if (hash_file('sha256', $settingsFile) !== hash('sha256', $before)) {
|
|
unlink($temporary);
|
|
throw new LogicException('Concurrent setting modification.');
|
|
}
|
|
if (! rename($temporary, $settingsFile)) {
|
|
throw new RuntimeException('Settings activation failed; prepared copy retained privately.');
|
|
}
|
|
$confirmed = json_decode(file_get_contents($settingsFile), true, 32, JSON_THROW_ON_ERROR);
|
|
if ($confirmed !== $after) {
|
|
throw new RuntimeException('Settings verification failed.');
|
|
}
|
|
$result = ['checked_at' => gmdate('c'), 'result' => 'passed', 'environment' => 'http://127.0.0.1:8005', 'authorization' => 'administrative-geography-installation-authorization.json', 'installation' => 'administrative-geography-installation.json', 'changed_setting' => 'SGC_GEOGRAPHY_ENABLED', 'selection_enabled' => true, 'other_settings_preserved' => true, 'settings_backup' => $backup, 'mfa_enabled' => false, 'business_commands' => false, 'automatic_classification' => false];
|
|
file_put_contents($root.'/docs/proofs/administrative-geography-activation.json', json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL);
|
|
echo 'Geographic selection enabled only in the local pilot; all other settings preserved.'.PHP_EOL;
|