{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/RelationController.php",
"old_string": " \/**\n * POST \/semantic-explorer\/relationen\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $type = trim($input['relation_type'] ?? '');\n $strength = (float) ($input['strength'] ?? 1.0);\n\n if ($type === '') {\n $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $this->relationRepository->update($id, $type, $strength);\n $this->json($this->apiFormatter->ok('Relation aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/relationen\/{id}\/delete\n *\/\n public function destroy(int $id): void\n {\n try {\n $this->relationRepository->delete($id);\n $this->json($this->apiFormatter->ok('Relation gelöscht'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}",
"new_string": " \/**\n * POST \/semantic-explorer\/relationen\/{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 $type = trim($input['relation_type'] ?? '');\n $strength = (float) ($input['strength'] ?? 1.0);\n\n if ($type === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Beziehungstyp ist erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $this->relationRepository->update($id, $type, $strength);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/relationen');\n\n return;\n }\n\n $this->json($this->apiFormatter->ok('Relation 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\/relationen\/{id}\/delete\n *\/\n public function destroy(int $id): void\n {\n $this->requireCsrf();\n\n try {\n $this->relationRepository->delete($id);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/relationen');\n\n return;\n }\n\n $this->json($this->apiFormatter->ok('Relation gelöscht'));\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\/RelationController.php",
"oldString": " \/**\n * POST \/semantic-explorer\/relationen\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $type = trim($input['relation_type'] ?? '');\n $strength = (float) ($input['strength'] ?? 1.0);\n\n if ($type === '') {\n $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $this->relationRepository->update($id, $type, $strength);\n $this->json($this->apiFormatter->ok('Relation aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/relationen\/{id}\/delete\n *\/\n public function destroy(int $id): void\n {\n try {\n $this->relationRepository->delete($id);\n $this->json($this->apiFormatter->ok('Relation gelöscht'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}",
"newString": " \/**\n * POST \/semantic-explorer\/relationen\/{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 $type = trim($input['relation_type'] ?? '');\n $strength = (float) ($input['strength'] ?? 1.0);\n\n if ($type === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Beziehungstyp ist erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $this->relationRepository->update($id, $type, $strength);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/relationen');\n\n return;\n }\n\n $this->json($this->apiFormatter->ok('Relation 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\/relationen\/{id}\/delete\n *\/\n public function destroy(int $id): void\n {\n $this->requireCsrf();\n\n try {\n $this->relationRepository->delete($id);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/relationen');\n\n return;\n }\n\n $this->json($this->apiFormatter->ok('Relation gelöscht'));\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 Relationen (CRUD)\n\nuse Domain\\Repository\\EntityRepositoryInterface;\nuse Domain\\Repository\\RelationRepositoryInterface;\nuse Framework\\Controller;\nuse Infrastructure\\Formatter\\ApiResponseFormatter;\n\nclass RelationController extends Controller\n{\n private RelationRepositoryInterface $relationRepository;\n private EntityRepositoryInterface $entityRepository;\n private ApiResponseFormatter $apiFormatter;\n\n public function __construct(\n RelationRepositoryInterface $relationRepository,\n EntityRepositoryInterface $entityRepository,\n ApiResponseFormatter $apiFormatter\n ) {\n $this->relationRepository = $relationRepository;\n $this->entityRepository = $entityRepository;\n $this->apiFormatter = $apiFormatter;\n }\n\n \/**\n * GET \/semantic-explorer\/relationen\n * Beziehungen zwischen Entitaeten\n *\/\n public function index(): void\n {\n $type = $this->getString('type');\n\n $relations = $this->relationRepository->findFiltered($type);\n $relationTypes = $this->relationRepository->getTypes();\n $stats = $this->relationRepository->getStats();\n\n $this->view('semantic-explorer.relationen', [\n 'title' => 'Relationen',\n 'relations' => $relations,\n 'relationTypes' => $relationTypes,\n 'stats' => $stats,\n 'currentType' => $type,\n ]);\n }\n\n \/**\n * GET \/semantic-explorer\/relationen\/new\n *\/\n public function create(): void\n {\n $this->view('semantic-explorer.relationen.new', [\n 'title' => 'Neue Relation',\n 'entities' => $this->entityRepository->findAllSimple(),\n 'relationTypes' => $this->relationRepository->getTypesList(),\n ]);\n }\n\n \/**\n * POST \/semantic-explorer\/relationen\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 $sourceId = (int) ($input['source_entity_id'] ?? 0);\n $targetId = (int) ($input['target_entity_id'] ?? 0);\n $type = trim($input['relation_type'] ?? '');\n $strength = (float) ($input['strength'] ?? 1.0);\n\n if ($sourceId === 0 || $targetId === 0 || $type === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Alle Felder sind erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Alle Felder sind erforderlich'), 400);\n\n return;\n }\n\n try {\n $id = $this->relationRepository->create($sourceId, $targetId, $type, $strength);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/relationen');\n\n return;\n }\n\n $this->json($this->apiFormatter->created($id, 'Relation 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\/relationen\/{id}\/edit\n *\/\n public function edit(int $id): void\n {\n $relation = $this->relationRepository->find($id);\n\n if ($relation === null) {\n $this->notFound('Relation nicht gefunden');\n }\n\n $this->view('semantic-explorer.relationen.edit', [\n 'title' => 'Relation bearbeiten',\n 'relation' => $relation,\n 'relationTypes' => $this->relationRepository->getTypesList(),\n ]);\n }\n\n \/**\n * POST \/semantic-explorer\/relationen\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $type = trim($input['relation_type'] ?? '');\n $strength = (float) ($input['strength'] ?? 1.0);\n\n if ($type === '') {\n $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $this->relationRepository->update($id, $type, $strength);\n $this->json($this->apiFormatter->ok('Relation aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/relationen\/{id}\/delete\n *\/\n public function destroy(int $id): void\n {\n try {\n $this->relationRepository->delete($id);\n $this->json($this->apiFormatter->ok('Relation gelöscht'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n}\n",
"structuredPatch": [
{
"oldStart": 131,
"oldLines": 12,
"newStart": 131,
"newLines": 22,
"lines": [
" *\/",
" public function update(int $id): void",
" {",
"+ $this->requireCsrf();",
"+",
" $input = $this->getJsonInput();",
"+ if (empty($input)) {",
"+ $input = $_POST;",
"+ }",
" ",
" $type = trim($input['relation_type'] ?? '');",
" $strength = (float) ($input['strength'] ?? 1.0);",
" ",
" if ($type === '') {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError('Beziehungstyp ist erforderlich');",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->validationError('Beziehungstyp ist erforderlich', ['relation_type' => 'Pflichtfeld']), 400);",
" ",
" return;"
]
},
{
"oldStart": 144,
"oldLines": 8,
"newStart": 154,
"newLines": 20,
"lines": [
" ",
" try {",
" $this->relationRepository->update($id, $type, $strength);",
"+",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxRedirect('\/semantic-explorer\/relationen');",
"+",
"+ return;",
"+ }",
"+",
" $this->json($this->apiFormatter->ok('Relation aktualisiert'));",
" } catch (\\Exception $e) {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError($e->getMessage());",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);",
" }",
" }"
]
},
{
"oldStart": 155,
"oldLines": 10,
"newStart": 177,
"newLines": 24,
"lines": [
" *\/",
" public function destroy(int $id): void",
" {",
"+ $this->requireCsrf();",
"+",
" try {",
" $this->relationRepository->delete($id);",
"+",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxRedirect('\/semantic-explorer\/relationen');",
"+",
"+ return;",
"+ }",
"+",
" $this->json($this->apiFormatter->ok('Relation gelöscht'));",
" } 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
}
}