#!/bin/bash

# Fix Laravel cache directory permissions

echo "Fixing Laravel cache permissions..."

# Create cache directories if they don't exist
mkdir -p /home/opstest/public_html/central-new/storage/framework/cache/data
mkdir -p /home/opstest/public_html/central-new/storage/framework/sessions
mkdir -p /home/opstest/public_html/central-new/storage/framework/views
mkdir -p /home/opstest/public_html/central-new/storage/logs
mkdir -p /home/opstest/public_html/central-new/bootstrap/cache

# Create all possible cache subdirectories (00-ff)
for i in {0..9} {a..f}; do
    for j in {0..9} {a..f}; do
        mkdir -p "/home/opstest/public_html/central-new/storage/framework/cache/data/${i}${j}"
        # Create second level subdirectories
        for k in {0..9} {a..f}; do
            for l in {0..9} {a..f}; do
                mkdir -p "/home/opstest/public_html/central-new/storage/framework/cache/data/${i}${j}/${k}${l}"
            done
        done
    done
done

echo "Cache directories created successfully!"

# Clear all caches
/opt/cpanel/ea-php84/root/usr/bin/php /home/opstest/public_html/central-new/artisan cache:clear
/opt/cpanel/ea-php84/root/usr/bin/php /home/opstest/public_html/central-new/artisan config:clear
/opt/cpanel/ea-php84/root/usr/bin/php /home/opstest/public_html/central-new/artisan view:clear

echo "All caches cleared!"
echo "Done!"