{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/EntityController.php",
"old_string": " \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $type = trim($input['type'] ?? '');\n $description = trim($input['description'] ?? '') ?: null;\n\n if ($name === '' || $type === '') {\n $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $this->repository->update($id, $name, $type, $description);\n $this->json($this->apiFormatter->ok('Entität aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\/delete\n *\/\n public function delete(int $id): void\n {\n try {\n $success = $this->repository->delete($id);\n if ($success) {\n $this->json($this->apiFormatter->ok('Entität gelöscht'));\n } else {\n $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);\n }\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}",
"new_string": " \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\n *\/\n public function update(int $id): void\n {\n $this->requireCsrf();\n\n $input = $this->getJsonInput();\n if (empty($input)) {\n $input = $_POST;\n }\n\n $name = trim($input['name'] ?? '');\n $type = trim($input['type'] ?? '');\n $description = trim($input['description'] ?? '') ?: null;\n\n if ($name === '' || $type === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Name und Typ sind erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $this->repository->update($id, $name, $type, $description);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/entitaeten\/' . $id);\n\n return;\n }\n\n $this->json($this->apiFormatter->ok('Entität aktualisiert'));\n } catch (\\Exception $e) {\n if ($this->isHtmxRequest()) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\/delete\n *\/\n public function delete(int $id): void\n {\n $this->requireCsrf();\n\n try {\n $success = $this->repository->delete($id);\n if ($success) {\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/entitaeten');\n\n return;\n }\n $this->json($this->apiFormatter->ok('Entität gelöscht'));\n } else {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Entität hat noch Relationen');\n\n return;\n }\n $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);\n }\n } catch (\\Exception $e) {\n if ($this->isHtmxRequest()) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/EntityController.php",
"oldString": " \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $type = trim($input['type'] ?? '');\n $description = trim($input['description'] ?? '') ?: null;\n\n if ($name === '' || $type === '') {\n $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $this->repository->update($id, $name, $type, $description);\n $this->json($this->apiFormatter->ok('Entität aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\/delete\n *\/\n public function delete(int $id): void\n {\n try {\n $success = $this->repository->delete($id);\n if ($success) {\n $this->json($this->apiFormatter->ok('Entität gelöscht'));\n } else {\n $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);\n }\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}",
"newString": " \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\n *\/\n public function update(int $id): void\n {\n $this->requireCsrf();\n\n $input = $this->getJsonInput();\n if (empty($input)) {\n $input = $_POST;\n }\n\n $name = trim($input['name'] ?? '');\n $type = trim($input['type'] ?? '');\n $description = trim($input['description'] ?? '') ?: null;\n\n if ($name === '' || $type === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Name und Typ sind erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $this->repository->update($id, $name, $type, $description);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/entitaeten\/' . $id);\n\n return;\n }\n\n $this->json($this->apiFormatter->ok('Entität aktualisiert'));\n } catch (\\Exception $e) {\n if ($this->isHtmxRequest()) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\/delete\n *\/\n public function delete(int $id): void\n {\n $this->requireCsrf();\n\n try {\n $success = $this->repository->delete($id);\n if ($success) {\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/entitaeten');\n\n return;\n }\n $this->json($this->apiFormatter->ok('Entität gelöscht'));\n } else {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Entität hat noch Relationen');\n\n return;\n }\n $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);\n }\n } catch (\\Exception $e) {\n if ($this->isHtmxRequest()) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Controller;\n\n\/\/ @responsibility: HTTP-Endpunkte für Semantic Explorer Entitäten (CRUD)\n\nuse Domain\\Repository\\EntityRepositoryInterface;\nuse Framework\\Controller;\nuse Infrastructure\\Formatter\\ApiResponseFormatter;\n\nclass EntityController extends Controller\n{\n private EntityRepositoryInterface $repository;\n private ApiResponseFormatter $apiFormatter;\n\n public function __construct(\n EntityRepositoryInterface $repository,\n ApiResponseFormatter $apiFormatter\n ) {\n $this->repository = $repository;\n $this->apiFormatter = $apiFormatter;\n }\n\n \/**\n * GET \/semantic-explorer\/entitaeten\n * Liste aller Entitaeten\n *\/\n public function index(): void\n {\n $type = $this->getString('type');\n $search = $this->getString('search');\n\n $entities = $this->repository->findFiltered($type, $search);\n $stats = $this->repository->getStats();\n\n $this->view('semantic-explorer.entitaeten.index', [\n 'title' => 'Entitaeten',\n 'entities' => $entities,\n 'stats' => $stats,\n 'currentType' => $type,\n 'currentSearch' => $search,\n ]);\n }\n\n \/**\n * GET \/semantic-explorer\/entitaeten\/{id}\n * Entitaet-Details\n *\/\n public function show(int $id): void\n {\n $entity = $this->repository->find($id);\n\n if ($entity === null) {\n $this->notFound('Entitaet nicht gefunden');\n }\n\n $synonyms = $this->repository->findSynonyms($id);\n $outgoingRelations = $this->repository->getOutgoingRelations($id);\n $incomingRelations = $this->repository->getIncomingRelations($id);\n $chunks = $this->repository->findChunks($id);\n $classifications = $this->repository->findClassifications($id);\n\n $this->view('semantic-explorer.entitaeten.show', [\n 'title' => $entity['name'],\n 'entity' => $entity,\n 'synonyms' => $synonyms,\n 'outgoingRelations' => $outgoingRelations,\n 'incomingRelations' => $incomingRelations,\n 'chunks' => $chunks,\n 'classifications' => $classifications,\n ]);\n }\n\n \/**\n * GET \/semantic-explorer\/entitaeten\/new\n *\/\n public function create(): void\n {\n $this->view('semantic-explorer.entitaeten.new', [\n 'title' => 'Neue Entitaet',\n 'types' => $this->repository->getTypes(),\n ]);\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\n *\/\n public function store(): void\n {\n $this->requireCsrf();\n\n $input = $this->getJsonInput();\n if (empty($input)) {\n $input = $_POST;\n }\n\n $name = trim($input['name'] ?? '');\n $type = trim($input['type'] ?? '');\n $description = trim($input['description'] ?? '') ?: null;\n\n if ($name === '' || $type === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Name und Typ sind erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $id = $this->repository->create($name, $type, $description);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/entitaeten\/' . $id);\n\n return;\n }\n\n $this->json($this->apiFormatter->created($id, 'Entität erstellt'));\n } catch (\\Exception $e) {\n if ($this->isHtmxRequest()) {\n $this->htmxError($e->getMessage());\n\n return;\n }\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * GET \/semantic-explorer\/entitaeten\/{id}\/edit\n *\/\n public function edit(int $id): void\n {\n $entity = $this->repository->find($id);\n\n if ($entity === null) {\n $this->notFound('Entitaet nicht gefunden');\n }\n\n $this->view('semantic-explorer.entitaeten.edit', [\n 'title' => 'Entitaet bearbeiten',\n 'entity' => $entity,\n 'types' => $this->repository->getTypes(),\n ]);\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $type = trim($input['type'] ?? '');\n $description = trim($input['description'] ?? '') ?: null;\n\n if ($name === '' || $type === '') {\n $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $this->repository->update($id, $name, $type, $description);\n $this->json($this->apiFormatter->ok('Entität aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/entitaeten\/{id}\/delete\n *\/\n public function delete(int $id): void\n {\n try {\n $success = $this->repository->delete($id);\n if ($success) {\n $this->json($this->apiFormatter->ok('Entität gelöscht'));\n } else {\n $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);\n }\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}\n",
"structuredPatch": [
{
"oldStart": 154,
"oldLines": 13,
"newStart": 154,
"newLines": 23,
"lines": [
" *\/",
" public function update(int $id): void",
" {",
"+ $this->requireCsrf();",
"+",
" $input = $this->getJsonInput();",
"+ if (empty($input)) {",
"+ $input = $_POST;",
"+ }",
" ",
" $name = trim($input['name'] ?? '');",
" $type = trim($input['type'] ?? '');",
" $description = trim($input['description'] ?? '') ?: null;",
" ",
" if ($name === '' || $type === '') {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError('Name und Typ sind erforderlich');",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->validationError('Name und Typ sind erforderlich'), 400);",
" ",
" return;"
]
},
{
"oldStart": 168,
"oldLines": 8,
"newStart": 178,
"newLines": 20,
"lines": [
" ",
" try {",
" $this->repository->update($id, $name, $type, $description);",
"+",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxRedirect('\/semantic-explorer\/entitaeten\/' . $id);",
"+",
"+ return;",
"+ }",
"+",
" $this->json($this->apiFormatter->ok('Entität aktualisiert'));",
" } catch (\\Exception $e) {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError($e->getMessage());",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);",
" }",
" }"
]
},
{
"oldStart": 179,
"oldLines": 14,
"newStart": 201,
"newLines": 31,
"lines": [
" *\/",
" public function delete(int $id): void",
" {",
"+ $this->requireCsrf();",
"+",
" try {",
" $success = $this->repository->delete($id);",
" if ($success) {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxRedirect('\/semantic-explorer\/entitaeten');",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->ok('Entität gelöscht'));",
" } else {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError('Entität hat noch Relationen');",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->error('Entität hat noch Relationen', 'HAS_RELATIONS'), 400);",
" }",
" } catch (\\Exception $e) {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError($e->getMessage());",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);",
" }",
" }"
]
}
],
"userModified": false,
"replaceAll": false
}
}