'pilot-readonly', 'APP_DEBUG' => 'false', 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '', 'PGOPTIONS' => '-c default_transaction_read_only=on', 'COMPRAS_INVENTORY_CONVERSION_ENABLED' => 'true', 'COMPRAS_INVENTORY_ROOT' => $candidate, 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array', 'QUEUE_CONNECTION' => 'null', 'MAIL_MAILER' => 'array', 'APP_CONFIG_CACHE' => $root.'/storage/framework/absent-inventory-readonly-config.php', 'LOG_CHANNEL' => 'stderr']; foreach ($environment as $key => $value) { putenv($key.'='.$value); $_ENV[$key] = $_SERVER[$key] = $value; } $app = require $root.'/bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); if (DB::selectOne('SHOW default_transaction_read_only')->default_transaction_read_only !== 'on') { throw new LogicException('Database read-only enforcement required.'); } // Conservation belongs to this inspection. Installation-time conservation remains // in the immutable installation proof; an operating application may advance its queue. DB::beginTransaction(); DB::statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY'); $frames = static function (): array { $result = []; foreach (DB::select("SELECT tablename FROM pg_tables WHERE schemaname='public' ORDER BY tablename") as $table) { $quoted = '"'.str_replace('"', '""', $table->tablename).'"'; $rows = DB::select('SELECT row_to_json(t)::text AS row FROM '.$quoted.' t ORDER BY row_to_json(t)::text'); $result[$table->tablename] = hash('sha256', json_encode(array_column($rows, 'row'), JSON_THROW_ON_ERROR)); } return $result; }; $baseline = $frames(); if (! app(InventoryConversionRuntime::class)->available()) { throw new LogicException('Candidate unavailable with prospective configuration.'); } app(ReceiptStockMovement::class)->load(); $converted = DB::table('goods_receipt_items')->whereNotNull('snapshot->quantity_conversion')->count(); if ($frames() !== $baseline) { throw new LogicException('Inventory inspection changed pilot data.'); } $preserved = count($baseline); DB::commit(); if (! hash_equals($sourceHash, hash_file('sha256', $sourcePath)) || ! hash_equals($publicHash, hash_file('sha256', $root.'/public/build/manifest.json'))) { throw new LogicException('Concurrent pilot settings or frontend change.'); } $result = ['date' => gmdate('c'), 'state' => 'passed', 'mode' => $installed ? 'installed_read_only_postcheck' : 'prospective_read_only_preflight', 'database_enforced_read_only' => true, 'candidate_available_with_installed_financial_runtime' => true, 'inventory_manifest_sha256' => InventoryConversionRuntime::MANIFEST_SHA256, 'active_settings_sha256' => $sourceHash, 'public_manifest_sha256' => $publicHash, 'existing_converted_receipt_lines' => $converted, 'active_settings_changed' => false, 'database_tables_preserved_during_readonly_check' => $preserved, 'inventory_component_installed_or_activated' => $installed, 'migrations_or_business_commands' => false]; file_put_contents($root.'/docs/proofs/inventory-conversion-pilot-'.($installed ? 'current-check' : 'preflight').'.json', json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL); echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;