option('silent'); // Show warning if not in framework developer mode $is_framework_dev = config('rsx.code_quality.is_framework_developer', false); if (!$is_framework_dev && !$silent) { $this->warn('⚠️ Running rsx:clean is rarely necessary'); $this->line(''); $this->line(' The manifest system automatically detects and rebuilds when files change.'); $this->line(' Manual cache clearing only adds 30-60 seconds to the next request.'); $this->line(''); $this->line(' Only run this command if:'); $this->line(' • Catastrophic errors require a fresh start'); $this->line(' • Framework code itself was updated outside normal workflows'); $this->line(' • Explicitly instructed by framework documentation'); $this->line(''); $this->line(' Consider removing rsx:clean from your development workflow.'); $this->newLine(); } if (!$silent) { $this->info('🧹 Cleaning RSX caches...'); $this->newLine(); } $cleaned_items = []; // 1. Clear rsx-build directory recursively - EVERYTHING $build_path = storage_path('rsx-build'); if (is_dir($build_path)) { $this->clear_directory($build_path); $cleaned_items[] = '✓ Build storage cleaned'; } // 2. Clear rsx-tmp directory recursively - EVERYTHING $tmp_path = storage_path('rsx-tmp'); if (is_dir($tmp_path)) { $this->clear_directory($tmp_path); $cleaned_items[] = '✓ Temp storage cleaned'; } // 3. Clear Redis cache directly without loading framework try { $redis = \Illuminate\Support\Facades\Redis::connection(); $redis->flushdb(); $cleaned_items[] = '✓ Redis cache cleared'; } catch (Exception $e) { $cleaned_items[] = '⊘ Redis cache skipped (not configured or unreachable)'; } // Note: We never clear rsx-locks directory as it contains active lock files // Display results if (!$silent) { if (empty($cleaned_items)) { $this->info('Nothing to clean - all caches already empty'); } else { foreach ($cleaned_items as $item) { $this->line(" $item"); } $this->newLine(); $this->info('✅ RSX caches cleaned successfully'); } } return 0; } /** * Clean a directory recursively * * @param string $path * @return void */ protected function clear_directory($path) { if (!is_dir($path)) { return; } $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($files as $file) { if ($file->isDir()) { rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } } /** * Count files in a directory recursively * * @param string $path * @return int */ protected function count_files_in_directory($path) { if (!is_dir($path)) { return 0; } $count = 0; $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $file) { if ($file->isFile()) { $count++; } } return $count; } }