<?php
/**
 * Temporary cache clear script
 * Run once via browser, then delete this file.
 */

if (empty($_GET['run']) || $_GET['run'] !== 'fix') {
    http_response_code(403);
    echo 'Access denied. Use: ' . htmlspecialchars($_SERVER['REQUEST_URI'] ?? '') . '?run=fix';
    exit;
}

require __DIR__ . '/../vendor/autoload.php';

$app = require_once __DIR__ . '/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$kernel->handle($request = Illuminate\Http\Request::capture());

use Illuminate\Support\Facades\Artisan;

Artisan::call('cache:clear');
Artisan::call('view:clear');
Artisan::call('config:clear');

if (function_exists('opcache_reset')) {
    opcache_reset();
}

echo 'All caches cleared. Please <strong>delete this file</strong> (public/fix-live-chat.php) now.<br>';
echo 'Then hard-refresh your website (Ctrl+F5).';
