<?php
/**
 * Brokam WEBSITE — one-time installer.
 * Visit:  https://brokaminternational.com/__setup.php?token=c9ec3a843e7e10e1648bc483ad7fae50
 * It runs the database migrations + seed, then you MUST DELETE this file.
 *
 * Path assumption: the website's public/ has been moved into public_html, and the
 * app core lives in a sibling folder named "brokam_web". Adjust $base if you named it differently.
 */
$TOKEN = 'c9ec3a843e7e10e1648bc483ad7fae50';
if (! isset($_GET['token']) || ! hash_equals($TOKEN, (string) $_GET['token'])) {
    http_response_code(403);
    exit('Forbidden');
}
@set_time_limit(300);
header('Content-Type: text/plain');

$base = __DIR__ . '/../brokam_web';
if (! is_file($base . '/vendor/autoload.php')) {
    exit("Cannot find the app at {$base}. Edit \$base in __setup.php to your app folder.\n");
}

require $base . '/vendor/autoload.php';
$app = require $base . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

echo "== migrate ==\n";
$kernel->call('migrate', ['--force' => true]);
echo $kernel->output();

echo "\n== db:seed ==\n";
$kernel->call('db:seed', ['--force' => true]);
echo $kernel->output();

echo "\n\n==== DONE ====\nDelete __setup.php from public_html NOW, then sign in and change the admin password.\n";
