68 lines
4.1 KiB
PHP
68 lines
4.1 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Console\Kernel;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Vite;
|
|
|
|
$root = dirname(__DIR__);
|
|
$directory = $root.'/storage/app/private/investmoz-v2';
|
|
$proof = json_decode(file_get_contents($directory.'/territory-backup-proof.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$target = $proof['restored_target'];
|
|
if (! preg_match('/^desk_restore_\d{8}_\d{6}_test$/', $target['database']) || (int) $target['port'] !== 55441) {
|
|
throw new RuntimeException('Isolated restored QA target required.');
|
|
}
|
|
foreach (['APP_ENV' => 'testing', 'APP_DEBUG' => 'true', 'APP_URL' => 'http://127.0.0.1:18093', 'APP_KEY' => 'base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', 'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441', 'DB_DATABASE' => $target['database'], 'DB_USERNAME' => 'postgres', 'DB_PASSWORD' => '', 'DB_URL' => '', 'SESSION_DRIVER' => 'file', 'SESSION_COOKIE' => 'territory_traceability_qa', 'CACHE_STORE' => 'array', 'QUEUE_CONNECTION' => 'sync'] as $key => $value) {
|
|
putenv($key.'='.$value);
|
|
$_ENV[$key] = $_SERVER[$key] = $value;
|
|
}
|
|
require $root.'/vendor/autoload.php';
|
|
$app = require $root.'/bootstrap/app.php';
|
|
$app->make(Kernel::class)->bootstrap();
|
|
$c = config('database.connections.pgsql');
|
|
if (config('database.default') !== 'pgsql' || $c['host'] !== '127.0.0.1' || (int) $c['port'] !== 55441 || $c['database'] !== $target['database'] || ! empty($c['url'])) {
|
|
throw new RuntimeException('Refusing non-QA configuration.');
|
|
}
|
|
$identity = DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port');
|
|
if ($identity->database !== $target['database'] || (int) $identity->port !== 55441) {
|
|
throw new RuntimeException('Refusing non-QA connection.');
|
|
}
|
|
$qa = $directory.'/qa-traceability-browser';
|
|
if (! is_dir($qa.'/sessions')) {
|
|
mkdir($qa.'/sessions', 0700, true);
|
|
}
|
|
config(['session.files' => $qa.'/sessions', 'portal.managers' => ['territory-browser@example.invalid'], 'investment.traceability_directory' => $qa, 'investment.repair_directory' => $qa, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
|
Vite::useHotFile($root.'/storage/framework/territory-qa-absent-hot');
|
|
if (PHP_SAPI === 'cli' && ($argv[1] ?? '') === 'seed') {
|
|
$user = User::updateOrCreate(['email' => 'territory-browser@example.invalid'], ['name' => 'Territory browser QA', 'password' => Hash::make('Territory-QA-2026!'), 'email_verified_at' => now()]);
|
|
$user->forceFill(['email_verified_at' => now()])->save();
|
|
$plan = json_decode(file_get_contents($directory.'/territory-activation-plan.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
$plan['target'] = $target;
|
|
$plan['prepared_at'] = gmdate('c');
|
|
foreach ($plan['guards'] as &$guard) {
|
|
if ($guard['table'] === 'cluster_projects') {
|
|
$row = DB::table('cluster_projects')->where('id', $guard['id'])->first();
|
|
foreach (array_keys($guard['expected']) as $field) {
|
|
$guard['expected'][$field] = $row->$field;
|
|
}
|
|
}
|
|
}
|
|
unset($guard);
|
|
$bytes = json_encode($plan, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
|
|
file_put_contents($qa.'/territory-activation-plan.json', $bytes);
|
|
file_put_contents($qa.'/territory-backup-proof.json', json_encode([...$proof, 'target' => $target, 'plan_hash' => hash('sha256', $bytes), 'fixture_only' => true], JSON_THROW_ON_ERROR));
|
|
file_put_contents($qa.'/preview.json', json_encode(['target' => $target, 'locations' => [], 'memberships' => [], 'pending' => [], 'prepared_opportunities' => []], JSON_THROW_ON_ERROR));
|
|
echo json_encode(['target' => $target, 'seeded_qa_user' => $user->id, 'active_writes' => 0]).PHP_EOL;
|
|
exit;
|
|
}
|
|
$path = rawurldecode(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
|
|
$asset = realpath($root.'/public'.$path);
|
|
$public = realpath($root.'/public');
|
|
if ($path !== '/' && $asset && $public && str_starts_with($asset, $public.DIRECTORY_SEPARATOR) && is_file($asset)) {
|
|
return false;
|
|
}
|
|
header('X-Investmoz-QA-Target: '.$identity->database.':'.$identity->port);
|
|
$app->handleRequest(Request::capture());
|