{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/BackupRestoreController.php",
"old_string": " \/**\n * POST \/backup-restore\/{id}\/restore\n * Restore file from backup.\n *\/\n public function restore(string $id): void\n {\n $this->requireCsrf();\n\n try {\n $this->repository->restore((int) $id);\n\n \/\/ Redirect with success message\n header('Location: \/backup-restore\/' . $id . '?restored=1');\n } catch (\\RuntimeException $e) {\n \/\/ Redirect with error message\n header('Location: \/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));\n }\n }",
"new_string": " \/**\n * POST \/backup-restore\/{id}\/restore\n * Restore file from backup.\n *\/\n public function restore(string $id): void\n {\n $this->requireCsrf();\n\n $isHtmx = $this->isHtmxRequest();\n\n try {\n $this->repository->restore((int) $id);\n\n if ($isHtmx) {\n $this->htmxRedirect('\/backup-restore\/' . $id . '?restored=1');\n\n return;\n }\n\n $this->redirect('\/backup-restore\/' . $id . '?restored=1');\n } catch (\\RuntimeException $e) {\n if ($isHtmx) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n\n $this->redirect('\/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));\n }\n }"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/BackupRestoreController.php",
"oldString": " \/**\n * POST \/backup-restore\/{id}\/restore\n * Restore file from backup.\n *\/\n public function restore(string $id): void\n {\n $this->requireCsrf();\n\n try {\n $this->repository->restore((int) $id);\n\n \/\/ Redirect with success message\n header('Location: \/backup-restore\/' . $id . '?restored=1');\n } catch (\\RuntimeException $e) {\n \/\/ Redirect with error message\n header('Location: \/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));\n }\n }",
"newString": " \/**\n * POST \/backup-restore\/{id}\/restore\n * Restore file from backup.\n *\/\n public function restore(string $id): void\n {\n $this->requireCsrf();\n\n $isHtmx = $this->isHtmxRequest();\n\n try {\n $this->repository->restore((int) $id);\n\n if ($isHtmx) {\n $this->htmxRedirect('\/backup-restore\/' . $id . '?restored=1');\n\n return;\n }\n\n $this->redirect('\/backup-restore\/' . $id . '?restored=1');\n } catch (\\RuntimeException $e) {\n if ($isHtmx) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n\n $this->redirect('\/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));\n }\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Controller;\n\n\/\/ @responsibility: HTTP-Endpunkte für Datei-Backup und -Wiederherstellung\n\nuse Domain\\Repository\\FileBackupRepositoryInterface;\nuse Framework\\Controller;\n\nclass BackupRestoreController extends Controller\n{\n private FileBackupRepositoryInterface $repository;\n\n public function __construct(FileBackupRepositoryInterface $repository)\n {\n $this->repository = $repository;\n }\n\n \/**\n * GET \/backup-restore\n * List all backups.\n *\/\n public function index(): void\n {\n $filters = [];\n\n $search = $this->getString('search');\n if ($search !== '') {\n $filters['search'] = $search;\n }\n\n $changeType = $this->getString('change_type');\n if ($changeType !== '') {\n $filters['change_type'] = $changeType;\n }\n\n $limit = 50;\n $offset = $this->getInt('offset');\n\n $backups = $this->repository->findAll($filters, $limit, $offset);\n $total = $this->repository->count($filters);\n $stats = $this->repository->getStatistics();\n\n $this->view('backup-restore.index', [\n 'title' => 'File Backup',\n 'backups' => $backups,\n 'stats' => $stats,\n 'total' => $total,\n 'filters' => $filters,\n ]);\n }\n\n \/**\n * GET \/backup-restore\/{id}\n * Show backup details.\n *\/\n public function show(string $id): void\n {\n $backup = $this->repository->findById((int) $id);\n\n if ($backup === null) {\n $this->notFound('Backup nicht gefunden');\n }\n\n \/\/ Get content preview (max 500 lines)\n $contentPreview = $this->repository->getContentPreview((int) $id, 500);\n\n \/\/ Get other versions of this file\n $versions = $this->repository->findByFilePath($backup['file_path']);\n\n \/\/ Check if file currently exists\n $fileExists = file_exists($backup['file_path']);\n\n $this->view('backup-restore.show', [\n 'title' => 'Backup #' . $id,\n 'backup' => $backup,\n 'contentPreview' => $contentPreview,\n 'versions' => $versions,\n 'fileExists' => $fileExists,\n ]);\n }\n\n \/**\n * POST \/backup-restore\/{id}\/restore\n * Restore file from backup.\n *\/\n public function restore(string $id): void\n {\n $this->requireCsrf();\n\n try {\n $this->repository->restore((int) $id);\n\n \/\/ Redirect with success message\n header('Location: \/backup-restore\/' . $id . '?restored=1');\n } catch (\\RuntimeException $e) {\n \/\/ Redirect with error message\n header('Location: \/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));\n }\n }\n\n \/**\n * GET \/backup-restore\/{id}\/download\n * Download full backup content as file.\n *\/\n public function downloadBackup(string $id): void\n {\n $backup = $this->repository->findById((int) $id);\n\n if ($backup === null) {\n $this->notFound('Backup nicht gefunden');\n }\n\n $filename = basename($backup['file_path']) . '.backup-v' . $backup['version'];\n $this->download($backup['file_content'], $filename, 'text\/plain');\n }\n}\n",
"structuredPatch": [
{
"oldStart": 90,
"oldLines": 14,
"newStart": 90,
"newLines": 26,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"+ $isHtmx = $this->isHtmxRequest();",
"+",
" try {",
" $this->repository->restore((int) $id);",
" ",
"- \/\/ Redirect with success message",
"- header('Location: \/backup-restore\/' . $id . '?restored=1');",
"+ if ($isHtmx) {",
"+ $this->htmxRedirect('\/backup-restore\/' . $id . '?restored=1');",
"+",
"+ return;",
"+ }",
"+",
"+ $this->redirect('\/backup-restore\/' . $id . '?restored=1');",
" } catch (\\RuntimeException $e) {",
"- \/\/ Redirect with error message",
"- header('Location: \/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));",
"+ if ($isHtmx) {",
"+ $this->htmxError($e->getMessage());",
"+",
"+ return;",
"+ }",
"+",
"+ $this->redirect('\/backup-restore\/' . $id . '?error=' . urlencode($e->getMessage()));",
" }",
" }",
" "
]
}
],
"userModified": false,
"replaceAll": false
}
}