info('🔧 System Repair Service gestart...'); $this->line('═══════════════════════════════════════════════'); $checkOnly = $this->option('check'); $force = $this->option('force'); $full = $this->option('full'); $emuOnly = $this->option('emu'); $nitroOnly = $this->option('nitro'); $results = [ 'emulator' => null, 'nitro' => null, ]; if (! $nitroOnly) { $results['emulator'] = $this->repairEmulator($emuService, $checkOnly, $force, $full); } if (! $emuOnly) { $results['nitro'] = $this->repairNitro($nitroService, $checkOnly, $force, $full); } Cache::put(self::CACHE_KEY_LAST_REPAIR, now()->toIso8601String()); $emuOk = $results['emulator'] === null || ($results['emulator']['success'] ?? false); $nitroOk = $results['nitro'] === null || ($results['nitro']['success'] ?? false); $this->line('═══════════════════════════════════════════════'); if ($emuOk && $nitroOk) { $this->info('✅ Alle systemen OK'); return Command::SUCCESS; } return Command::FAILURE; } private function ensureBaseDirectories(): void { $basePaths = [ '/var/www', '/var/www/atomcms', storage_path('app'), ]; foreach ($basePaths as $path) { if (! is_dir($path)) { @mkdir($path, 0755, true); } } Process::timeout(5)->run('chown -R www-data:www-data /var/www/atomcms 2>/dev/null || true'); Process::timeout(5)->run('chmod -R 755 /var/www/atomcms 2>/dev/null || true'); } private function repairEmulator(EmulatorUpdateService $service, bool $checkOnly, bool $force, bool $full): array { $this->info('Emulator controleren...'); $this->ensureBaseDirectories(); try { $diagnosis = $service->diagnose(); if (empty($diagnosis['issues']) && ! $force && ! $full) { $this->line(' ✅ Emulator is OK'); return ['success' => true, 'status' => 'ok']; } if ($checkOnly) { $this->warn(' ⚠️ Emulator problemen gevonden:'); foreach ($diagnosis['issues'] ?? [] as $issue) { $this->line(' - ' . $issue); } foreach ($diagnosis['recommendations'] ?? [] as $rec) { $this->line(' 💡 ' . $rec); } return ['success' => false, 'status' => 'issues_found', 'issues' => $diagnosis['issues']]; } $this->warn(' 🔧 Emulator wordt gerepareerd...'); if ($full) { $this->line(' 📦 Volledige reset...'); $repairResult = $service->repairEmulator(); } else { $repairResult = $service->repairEmulator(); } if ($repairResult['success']) { $this->info(' ✅ Emulator gerepareerd!'); foreach ($repairResult['actions'] ?? [] as $action) { $this->line(' - ' . $action); } return ['success' => true, 'status' => 'repaired', 'actions' => $repairResult['actions']]; } $this->error(' ❌ Emulator repair mislukt: ' . ($repairResult['error'] ?? 'Onbekend')); if (! empty($repairResult['actions'])) { $this->line(' Uitgevoerde acties:'); foreach ($repairResult['actions'] as $action) { $this->line(' - ' . $action); } } return ['success' => false, 'status' => 'failed', 'error' => $repairResult['error']]; } catch (\Exception $e) { $this->error(' ❌ Emulator exception: ' . $e->getMessage()); Log::error('[SystemRepair] Emulator exception', ['error' => $e->getMessage()]); return ['success' => false, 'status' => 'exception', 'error' => $e->getMessage()]; } } private function repairNitro(NitroUpdateService $service, bool $checkOnly, bool $force, bool $full): array { $this->info('Nitro controleren...'); $this->ensureBaseDirectories(); try { $diagnosis = $service->diagnose(); if (empty($diagnosis['issues']) && ! $force && ! $full) { $this->line(' ✅ Nitro is OK'); return ['success' => true, 'status' => 'ok']; } if ($checkOnly) { $this->warn(' ⚠️ Nitro problemen gevonden:'); foreach ($diagnosis['issues'] ?? [] as $issue) { $this->line(' - ' . $issue); } foreach ($diagnosis['recommendations'] ?? [] as $rec) { $this->line(' 💡 ' . $rec); } return ['success' => false, 'status' => 'issues_found', 'issues' => $diagnosis['issues']]; } $this->warn(' 🔧 Nitro wordt gerepareerd...'); if ($full) { $this->line(' 📦 Volledige reset...'); $repairResult = $service->updateNitro(); } else { $repairResult = $service->repair(); } if ($repairResult['success']) { $this->info(' ✅ Nitro gerepareerd!'); foreach ($repairResult['actions'] ?? [] as $action) { $this->line(' - ' . $action); } return ['success' => true, 'status' => 'repaired', 'actions' => $repairResult['actions']]; } $this->error(' ❌ Nitro repair mislukt: ' . ($repairResult['error'] ?? 'Onbekend')); if (! empty($repairResult['actions'])) { $this->line(' Uitgevoerde acties:'); foreach ($repairResult['actions'] as $action) { $this->line(' - ' . $action); } } return ['success' => false, 'status' => 'failed', 'error' => $repairResult['error']]; } catch (\Exception $e) { $this->error(' ❌ Nitro exception: ' . $e->getMessage()); Log::error('[SystemRepair] Nitro exception', ['error' => $e->getMessage()]); return ['success' => false, 'status' => 'exception', 'error' => $e->getMessage()]; } } }