{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/PromptsController.php",
"oldString": " public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $id = $this->promptsRepo->create($name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function show(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function edit(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $criticCount = $this->promptsRepo->countLinkedCritics((int) $id);\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $this->promptsRepo->delete((int) $id);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0');\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n}",
"newString": " public function store(): void\n {\n $this->requireCsrf();\n\n $result = $this->promptsUseCase->create(\n name: $_POST['name'] ?? '',\n version: $_POST['version'] ?? '1.0',\n content: $_POST['content'] ?? '',\n isActive: isset($_POST['is_active'])\n );\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n header('Location: \/prompts\/new');\n exit;\n }\n\n $_SESSION['success'] = $result->message;\n header('Location: \/prompts\/' . $result->id);\n exit;\n }\n\n public function show(string $id): void\n {\n $prompt = $this->promptsUseCase->getById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.show', [\n 'title' => $prompt->name,\n 'prompt' => (array) $prompt,\n 'linkedCritics' => $this->promptsUseCase->getLinkedCritics((int) $id),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function edit(string $id): void\n {\n $prompt = $this->promptsUseCase->getById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt->name,\n 'prompt' => (array) $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $result = $this->promptsUseCase->update(\n id: (int) $id,\n name: $_POST['name'] ?? '',\n version: $_POST['version'] ?? '1.0',\n content: $_POST['content'] ?? '',\n isActive: isset($_POST['is_active'])\n );\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $_SESSION['success'] = $result->message;\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $result = $this->promptsUseCase->delete((int) $id);\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $_SESSION['success'] = $result->message;\n header('Location: \/prompts');\n exit;\n }\n\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $result = $this->promptsUseCase->duplicate((int) $id);\n\n if (!$result->success) {\n $_SESSION['error'] = $result->message;\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $_SESSION['success'] = $result->message;\n header('Location: \/prompts\/' . $result->id . '\/edit');\n exit;\n }\n}",
"originalFile": "<?php\n\nnamespace Controller;\n\nuse Framework\\Controller;\nuse UseCases\\Prompts\\ManagePromptsUseCase;\n\nclass PromptsController extends Controller\n{\n private ManagePromptsUseCase $promptsUseCase;\n\n private const PROMPT_TYPES = [\n 'critic' => 'Critic-Prompt',\n 'generate' => 'Generierungs-Prompt',\n 'revise' => 'Revisions-Prompt',\n 'system' => 'System-Prompt',\n 'other' => 'Sonstiges',\n ];\n\n public function __construct(?ManagePromptsUseCase $promptsUseCase = null)\n {\n $this->promptsUseCase = $promptsUseCase ?? new ManagePromptsUseCase();\n }\n\n public function index(): void\n {\n $this->view('prompts.index', [\n 'title' => 'Prompts verwalten',\n 'prompts' => array_map(fn ($dto) => (array) $dto, $this->promptsUseCase->getAll()),\n 'stats' => $this->promptsUseCase->getStatistics(),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function promptsNew(): void\n {\n $this->view('prompts.form', [\n 'title' => 'Neuer Prompt',\n 'prompt' => null,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => false,\n ]);\n }\n\n public function store(): void\n {\n $this->requireCsrf();\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/new');\n exit;\n }\n\n $id = $this->promptsRepo->create($name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt erfolgreich erstellt.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function show(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.show', [\n 'title' => $prompt['name'],\n 'prompt' => $prompt,\n 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id),\n 'promptTypes' => self::PROMPT_TYPES,\n ]);\n }\n\n public function edit(string $id): void\n {\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $this->view('prompts.form', [\n 'title' => 'Bearbeiten: ' . $prompt['name'],\n 'prompt' => $prompt,\n 'promptTypes' => self::PROMPT_TYPES,\n 'isEdit' => true,\n ]);\n }\n\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? $prompt['version']);\n $content = $_POST['content'] ?? '';\n $isActive = isset($_POST['is_active']) ? 1 : 0;\n\n if ($name === '' || $content === '') {\n $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';\n header('Location: \/prompts\/' . $id . '\/edit');\n exit;\n }\n\n $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive);\n\n $_SESSION['success'] = 'Prompt aktualisiert.';\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n public function delete(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $criticCount = $this->promptsRepo->countLinkedCritics((int) $id);\n if ($criticCount > 0) {\n $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";\n header('Location: \/prompts\/' . $id);\n exit;\n }\n\n $this->promptsRepo->delete((int) $id);\n\n $_SESSION['success'] = 'Prompt gelöscht.';\n header('Location: \/prompts');\n exit;\n }\n\n public function duplicate(string $id): void\n {\n $this->requireCsrf();\n\n $prompt = $this->promptsRepo->findById((int) $id);\n if ($prompt === null) {\n $this->notFound('Prompt nicht gefunden');\n }\n\n $newName = $prompt['name'] . ' (Kopie)';\n $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0');\n\n $_SESSION['success'] = 'Prompt dupliziert.';\n header('Location: \/prompts\/' . $newId . '\/edit');\n exit;\n }\n}\n",
"structuredPatch": [
{
"oldStart": 46,
"oldLines": 49,
"newStart": 46,
"newLines": 49,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"- $name = trim($_POST['name'] ?? '');",
"- $version = trim($_POST['version'] ?? '1.0');",
"- $content = $_POST['content'] ?? '';",
"- $isActive = isset($_POST['is_active']) ? 1 : 0;",
"+ $result = $this->promptsUseCase->create(",
"+ name: $_POST['name'] ?? '',",
"+ version: $_POST['version'] ?? '1.0',",
"+ content: $_POST['content'] ?? '',",
"+ isActive: isset($_POST['is_active'])",
"+ );",
" ",
"- if ($name === '' || $content === '') {",
"- $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';",
"+ if (!$result->success) {",
"+ $_SESSION['error'] = $result->message;",
" header('Location: \/prompts\/new');",
" exit;",
" }",
" ",
"- $id = $this->promptsRepo->create($name, $version, $content, $isActive);",
"-",
"- $_SESSION['success'] = 'Prompt erfolgreich erstellt.';",
"- header('Location: \/prompts\/' . $id);",
"+ $_SESSION['success'] = $result->message;",
"+ header('Location: \/prompts\/' . $result->id);",
" exit;",
" }",
" ",
" public function show(string $id): void",
" {",
"- $prompt = $this->promptsRepo->findById((int) $id);",
"+ $prompt = $this->promptsUseCase->getById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }",
" ",
" $this->view('prompts.show', [",
"- 'title' => $prompt['name'],",
"- 'prompt' => $prompt,",
"- 'linkedCritics' => $this->promptsRepo->findLinkedCritics((int) $id),",
"+ 'title' => $prompt->name,",
"+ 'prompt' => (array) $prompt,",
"+ 'linkedCritics' => $this->promptsUseCase->getLinkedCritics((int) $id),",
" 'promptTypes' => self::PROMPT_TYPES,",
" ]);",
" }",
" ",
" public function edit(string $id): void",
" {",
"- $prompt = $this->promptsRepo->findById((int) $id);",
"+ $prompt = $this->promptsUseCase->getById((int) $id);",
" if ($prompt === null) {",
" $this->notFound('Prompt nicht gefunden');",
" }",
" ",
" $this->view('prompts.form', [",
"- 'title' => 'Bearbeiten: ' . $prompt['name'],",
"- 'prompt' => $prompt,",
"+ 'title' => 'Bearbeiten: ' . $prompt->name,",
"+ 'prompt' => (array) $prompt,",
" 'promptTypes' => self::PROMPT_TYPES,",
" 'isEdit' => true,",
" ]);"
]
},
{
"oldStart": 98,
"oldLines": 25,
"newStart": 98,
"newLines": 21,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"- $prompt = $this->promptsRepo->findById((int) $id);",
"- if ($prompt === null) {",
"- $this->notFound('Prompt nicht gefunden');",
"- }",
"+ $result = $this->promptsUseCase->update(",
"+ id: (int) $id,",
"+ name: $_POST['name'] ?? '',",
"+ version: $_POST['version'] ?? '1.0',",
"+ content: $_POST['content'] ?? '',",
"+ isActive: isset($_POST['is_active'])",
"+ );",
" ",
"- $name = trim($_POST['name'] ?? '');",
"- $version = trim($_POST['version'] ?? $prompt['version']);",
"- $content = $_POST['content'] ?? '';",
"- $isActive = isset($_POST['is_active']) ? 1 : 0;",
"-",
"- if ($name === '' || $content === '') {",
"- $_SESSION['error'] = 'Name und Inhalt sind erforderlich.';",
"+ if (!$result->success) {",
"+ $_SESSION['error'] = $result->message;",
" header('Location: \/prompts\/' . $id . '\/edit');",
" exit;",
" }",
" ",
"- $this->promptsRepo->update((int) $id, $name, $version, $content, $isActive);",
"-",
"- $_SESSION['success'] = 'Prompt aktualisiert.';",
"+ $_SESSION['success'] = $result->message;",
" header('Location: \/prompts\/' . $id);",
" exit;",
" }"
]
},
{
"oldStart": 125,
"oldLines": 21,
"newStart": 121,
"newLines": 15,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"- $prompt = $this->promptsRepo->findById((int) $id);",
"- if ($prompt === null) {",
"- $this->notFound('Prompt nicht gefunden');",
"- }",
"+ $result = $this->promptsUseCase->delete((int) $id);",
" ",
"- $criticCount = $this->promptsRepo->countLinkedCritics((int) $id);",
"- if ($criticCount > 0) {",
"- $_SESSION['error'] = \"Kann nicht gelöscht werden: {$criticCount} Critics verknüpft.\";",
"+ if (!$result->success) {",
"+ $_SESSION['error'] = $result->message;",
" header('Location: \/prompts\/' . $id);",
" exit;",
" }",
" ",
"- $this->promptsRepo->delete((int) $id);",
"-",
"- $_SESSION['success'] = 'Prompt gelöscht.';",
"+ $_SESSION['success'] = $result->message;",
" header('Location: \/prompts');",
" exit;",
" }"
]
},
{
"oldStart": 148,
"oldLines": 16,
"newStart": 138,
"newLines": 16,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"- $prompt = $this->promptsRepo->findById((int) $id);",
"- if ($prompt === null) {",
"- $this->notFound('Prompt nicht gefunden');",
"+ $result = $this->promptsUseCase->duplicate((int) $id);",
"+",
"+ if (!$result->success) {",
"+ $_SESSION['error'] = $result->message;",
"+ header('Location: \/prompts\/' . $id);",
"+ exit;",
" }",
" ",
"- $newName = $prompt['name'] . ' (Kopie)';",
"- $newId = $this->promptsRepo->duplicate((int) $id, $newName, '1.0');",
"-",
"- $_SESSION['success'] = 'Prompt dupliziert.';",
"- header('Location: \/prompts\/' . $newId . '\/edit');",
"+ $_SESSION['success'] = $result->message;",
"+ header('Location: \/prompts\/' . $result->id . '\/edit');",
" exit;",
" }",
" }"
]
}
],
"userModified": false,
"replaceAll": false
}
}