repository = new FileBackupRepository(); } /** * GET /backup-restore * List all backups. */ public function index(): void { $filters = []; if (isset($_GET['search']) && $_GET['search'] !== '') { $filters['search'] = $_GET['search']; } if (isset($_GET['change_type']) && $_GET['change_type'] !== '') { $filters['change_type'] = $_GET['change_type']; } $limit = 50; $offset = (int) ($_GET['offset'] ?? 0); $backups = $this->repository->findAll($filters, $limit, $offset); $total = $this->repository->count($filters); $stats = $this->repository->getStatistics(); $this->view('backup-restore.index', [ 'title' => 'File Backup', 'backups' => $backups, 'stats' => $stats, 'total' => $total, 'filters' => $filters, ]); } /** * GET /backup-restore/{id} * Show backup details. */ public function show(string $id): void { $backup = $this->repository->findById((int) $id); if ($backup === null) { http_response_code(404); echo '404 - Backup nicht gefunden'; return; } // Get content preview (max 500 lines) $contentPreview = $this->repository->getContentPreview((int) $id, 500); // Get other versions of this file $versions = $this->repository->findByFilePath($backup['file_path']); // Check if file currently exists $fileExists = file_exists($backup['file_path']); $this->view('backup-restore.show', [ 'title' => 'Backup #' . $id, 'backup' => $backup, 'contentPreview' => $contentPreview, 'versions' => $versions, 'fileExists' => $fileExists, ]); } /** * POST /backup-restore/{id}/restore * Restore file from backup. */ public function restore(string $id): void { try { $this->repository->restore((int) $id); // Redirect with success message header('Location: /backup-restore/' . $id . '?restored=1'); } catch (\RuntimeException $e) { // Redirect with error message header('Location: /backup-restore/' . $id . '?error=' . urlencode($e->getMessage())); } } /** * GET /backup-restore/{id}/download * Download full backup content as file. */ public function download(string $id): void { $backup = $this->repository->findById((int) $id); if ($backup === null) { http_response_code(404); echo '404 - Backup nicht gefunden'; return; } $filename = basename($backup['file_path']) . '.backup-v' . $backup['version']; header('Content-Type: text/plain; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . strlen($backup['file_content'])); echo $backup['file_content']; } }