{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/TaxonomyController.php",
"old_string": " \/**\n * POST \/semantic-explorer\/taxonomie\n *\/\n public function store(): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;\n\n if ($name === '') {\n $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $id = $this->repository->create($name, $parentId);\n $this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff erstellt'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }",
"new_string": " \/**\n * POST \/semantic-explorer\/taxonomie\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 $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;\n\n if ($name === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Name ist erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $id = $this->repository->create($name, $parentId);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/taxonomie\/' . $id);\n\n return;\n }\n\n $this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff 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 }"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/TaxonomyController.php",
"oldString": " \/**\n * POST \/semantic-explorer\/taxonomie\n *\/\n public function store(): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;\n\n if ($name === '') {\n $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $id = $this->repository->create($name, $parentId);\n $this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff erstellt'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }",
"newString": " \/**\n * POST \/semantic-explorer\/taxonomie\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 $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;\n\n if ($name === '') {\n if ($this->isHtmxRequest()) {\n $this->htmxError('Name ist erforderlich');\n\n return;\n }\n $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $id = $this->repository->create($name, $parentId);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/semantic-explorer\/taxonomie\/' . $id);\n\n return;\n }\n\n $this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff 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 }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Controller;\n\n\/\/ @responsibility: HTTP-Endpunkte für Semantic Explorer Taxonomie (CRUD)\n\nuse Domain\\Repository\\TaxonomyRepositoryInterface;\nuse Framework\\Controller;\nuse Infrastructure\\Formatter\\ApiResponseFormatter;\n\nclass TaxonomyController extends Controller\n{\n private TaxonomyRepositoryInterface $repository;\n private ApiResponseFormatter $apiFormatter;\n\n public function __construct(\n TaxonomyRepositoryInterface $repository,\n ApiResponseFormatter $apiFormatter\n ) {\n $this->repository = $repository;\n $this->apiFormatter = $apiFormatter;\n }\n\n \/**\n * GET \/semantic-explorer\/taxonomie\n * Hierarchische Kategorisierung\n *\/\n public function index(): void\n {\n $terms = $this->repository->findAll();\n $hierarchy = $this->buildTaxonomyTree($terms);\n $stats = $this->repository->getStats();\n\n $this->view('semantic-explorer.taxonomie', [\n 'title' => 'Taxonomie',\n 'terms' => $terms,\n 'hierarchy' => $hierarchy,\n 'stats' => $stats,\n ]);\n }\n\n \/**\n * GET \/semantic-explorer\/taxonomie\/new\n *\/\n public function create(): void\n {\n $this->view('semantic-explorer.taxonomie.new', [\n 'title' => 'Neuer Taxonomie-Begriff',\n 'terms' => $this->repository->findForSelect(),\n ]);\n }\n\n \/**\n * POST \/semantic-explorer\/taxonomie\n *\/\n public function store(): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;\n\n if ($name === '') {\n $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $id = $this->repository->create($name, $parentId);\n $this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff erstellt'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * GET \/semantic-explorer\/taxonomie\/{id}\/edit\n *\/\n public function edit(int $id): void\n {\n $term = $this->repository->find($id);\n\n if ($term === null) {\n $this->notFound('Begriff nicht gefunden');\n }\n\n $this->view('semantic-explorer.taxonomie.edit', [\n 'title' => 'Begriff bearbeiten',\n 'term' => $term,\n 'terms' => $this->repository->findForSelect(),\n ]);\n }\n\n \/**\n * POST \/semantic-explorer\/taxonomie\/{id}\n *\/\n public function update(int $id): void\n {\n $input = $this->getJsonInput();\n\n $name = trim($input['name'] ?? '');\n $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;\n\n if ($name === '') {\n $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);\n\n return;\n }\n\n try {\n $this->repository->update($id, $name, $parentId);\n $this->json($this->apiFormatter->ok('Taxonomie-Begriff aktualisiert'));\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * POST \/semantic-explorer\/taxonomie\/{id}\/delete\n *\/\n public function destroy(int $id): void\n {\n try {\n $success = $this->repository->delete($id);\n if ($success) {\n $this->json($this->apiFormatter->ok('Taxonomie-Begriff gelöscht'));\n } else {\n $this->json($this->apiFormatter->error('Begriff hat noch Unterbegriffe', 'HAS_CHILDREN'), 400);\n }\n } catch (\\Exception $e) {\n $this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);\n }\n }\n\n \/**\n * Baut Baum aus flacher Liste\n *\/\n private function buildTaxonomyTree(array $items, ?int $parentId = null): array\n {\n $tree = [];\n foreach ($items as $item) {\n if ($item['parent_id'] == $parentId) {\n $item['children'] = $this->buildTaxonomyTree($items, $item['id']);\n $tree[] = $item;\n }\n }\n\n return $tree;\n }\n}\n",
"structuredPatch": [
{
"oldStart": 57,
"oldLines": 12,
"newStart": 57,
"newLines": 22,
"lines": [
" *\/",
" public function store(): void",
" {",
"+ $this->requireCsrf();",
"+",
" $input = $this->getJsonInput();",
"+ if (empty($input)) {",
"+ $input = $_POST;",
"+ }",
" ",
" $name = trim($input['name'] ?? '');",
" $parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;",
" ",
" if ($name === '') {",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxError('Name ist erforderlich');",
"+",
"+ return;",
"+ }",
" $this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);",
" ",
" return;"
]
},
{
"oldStart": 70,
"oldLines": 8,
"newStart": 80,
"newLines": 20,
"lines": [
" ",
" try {",
" $id = $this->repository->create($name, $parentId);",
"+",
"+ if ($this->isHtmxRequest()) {",
"+ $this->htmxRedirect('\/semantic-explorer\/taxonomie\/' . $id);",
"+",
"+ return;",
"+ }",
"+",
" $this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff erstellt'));",
" } 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
}
}