#!/bin/bash

# Fix Production Server Cache Issues
# Run this script on the production server via SSH

echo "=================================="
echo "Clearing Production Server Cache"
echo "=================================="

# Delete all cached files
rm -rf bootstrap/cache/*.php
echo "✓ Deleted bootstrap cache files"

# Clear all Laravel caches
php artisan optimize:clear
echo "✓ Cleared Laravel caches"

# Regenerate optimized autoloader
composer dump-autoload --optimize --no-dev
echo "✓ Regenerated autoloader"

# Rebuild cache for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
echo "✓ Rebuilt production caches"

# Clear OPcache (if using PHP-FPM)
if command -v systemctl &> /dev/null; then
    echo "Restarting PHP-FPM..."
    sudo systemctl restart php8.3-fpm || sudo systemctl restart php-fpm
    echo "✓ Restarted PHP-FPM"
fi

echo ""
echo "=================================="
echo "✅ Production cache cleared!"
echo "=================================="
echo ""
echo "Test your site: https://erp.karamkhallaf.com/admin"
