<?php

/**
 * Tech TMS - Laravel Application Cleanup
 *
 * Clears:
 *   - Configuration cache
 *   - Compiled Blade views
 *   - Application cache
 *
 * PHP: 7.4+
 */

$php = PHP_BINARY;
$artisan = __DIR__ . DIRECTORY_SEPARATOR . 'artisan';

echo "=============================================\n";
echo " Tech TMS - Laravel Application Cleanup\n";
echo "=============================================\n\n";

if (!file_exists($artisan)) {
    echo "ERROR: artisan file not found.\n";
    echo "Expected:\n";
    echo $artisan . "\n";
    exit(1);
}

$commands = [
    'config:clear',
    'view:clear',
    'cache:clear',
];

foreach ($commands as $command) {

    echo "Running: php artisan {$command}\n";
    echo "---------------------------------------------\n";

    $commandLine = '"' . $php . '" "' . $artisan . '" ' . $command;

    passthru($commandLine, $exitCode);

    echo "\n";

    if ($exitCode !== 0) {
        echo "ERROR: Command failed: {$command}\n";
        echo "Exit code: {$exitCode}\n\n";
    } else {
        echo "OK: {$command}\n\n";
    }
}

echo "=============================================\n";
echo " Cleanup completed\n";
echo "=============================================\n";