{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/TaxonomyRepository.php",
"oldString": " $depth = (int) $parent['depth'] + 1;",
"newString": " $depth = $parent['depth'] + 1;",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\Persistence;\n\n\/\/ @responsibility: CRUD-Operationen für Taxonomy-Begriffe (Hierarchie)\n\nuse Domain\\Repository\\TaxonomyRepositoryInterface;\nuse Infrastructure\\Config\\DatabaseFactory;\nuse PDO;\n\nfinal class TaxonomyRepository implements TaxonomyRepositoryInterface\n{\n private PDO $db;\n\n public function __construct()\n {\n $this->db = DatabaseFactory::content();\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function findAll(): array\n {\n return $this->db->query(\n 'SELECT t.*,\n COUNT(DISTINCT ct.chunk_id) as chunk_count,\n (SELECT COUNT(*) FROM taxonomy_terms WHERE parent_id = t.id) as children_count\n FROM taxonomy_terms t\n LEFT JOIN chunk_taxonomy ct ON t.id = ct.taxonomy_term_id\n GROUP BY t.id\n ORDER BY t.path, t.name'\n )->fetchAll();\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function getStats(): array\n {\n $result = $this->db->query(\n 'SELECT\n (SELECT COUNT(*) FROM taxonomy_terms) as total_terms,\n (SELECT COUNT(*) FROM taxonomy_terms WHERE parent_id IS NULL) as root_terms,\n (SELECT MAX(depth) FROM taxonomy_terms) as max_depth,\n (SELECT COUNT(DISTINCT chunk_id) FROM chunk_taxonomy) as tagged_chunks'\n )->fetch();\n\n return $result !== false ? $result : [\n 'total_terms' => 0,\n 'root_terms' => 0,\n 'max_depth' => 0,\n 'tagged_chunks' => 0,\n ];\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function find(int $id): ?array\n {\n $stmt = $this->db->prepare('SELECT * FROM taxonomy_terms WHERE id = :id');\n $stmt->execute(['id' => $id]);\n $result = $stmt->fetch();\n\n return $result === false ? null : $result;\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function create(string $name, ?int $parentId = null): int\n {\n $depth = 0;\n $path = $name;\n\n if ($parentId !== null) {\n $parent = $this->find($parentId);\n if ($parent !== null) {\n $depth = (int) $parent['depth'] + 1;\n $path = $parent['path'] . '\/' . $name;\n }\n }\n\n $stmt = $this->db->prepare(\n 'INSERT INTO taxonomy_terms (name, parent_id, depth, path, created_at)\n VALUES (:name, :parent, :depth, :path, NOW())'\n );\n $stmt->execute([\n 'name' => $name,\n 'parent' => $parentId,\n 'depth' => $depth,\n 'path' => $path,\n ]);\n\n return (int) $this->db->lastInsertId();\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function update(int $id, string $name, ?int $parentId = null): bool\n {\n $depth = 0;\n $path = $name;\n\n if ($parentId !== null) {\n $parent = $this->find($parentId);\n if ($parent !== null) {\n $depth = (int) $parent['depth'] + 1;\n $path = $parent['path'] . '\/' . $name;\n }\n }\n\n $stmt = $this->db->prepare(\n 'UPDATE taxonomy_terms SET name = :name, parent_id = :parent, depth = :depth, path = :path WHERE id = :id'\n );\n\n return $stmt->execute([\n 'id' => $id,\n 'name' => $name,\n 'parent' => $parentId,\n 'depth' => $depth,\n 'path' => $path,\n ]);\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function delete(int $id): bool\n {\n \/\/ Check for children\n $stmt = $this->db->prepare('SELECT COUNT(*) FROM taxonomy_terms WHERE parent_id = :id');\n $stmt->execute(['id' => $id]);\n\n if ((int) $stmt->fetchColumn() > 0) {\n return false; \/\/ Has children, cannot delete\n }\n\n \/\/ Delete chunk associations\n $stmt = $this->db->prepare('DELETE FROM chunk_taxonomy WHERE taxonomy_term_id = :id');\n $stmt->execute(['id' => $id]);\n\n \/\/ Delete term\n $stmt = $this->db->prepare('DELETE FROM taxonomy_terms WHERE id = :id');\n\n return $stmt->execute(['id' => $id]);\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function findForSelect(): array\n {\n return $this->db->query(\n 'SELECT id, name, depth, path FROM taxonomy_terms ORDER BY path, name'\n )->fetchAll();\n }\n}\n",
"structuredPatch": [
{
"oldStart": 79,
"oldLines": 7,
"newStart": 79,
"newLines": 7,
"lines": [
" if ($parentId !== null) {",
" $parent = $this->find($parentId);",
" if ($parent !== null) {",
"- $depth = (int) $parent['depth'] + 1;",
"+ $depth = $parent['depth'] + 1;",
" $path = $parent['path'] . '\/' . $name;",
" }",
" }"
]
},
{
"oldStart": 109,
"oldLines": 7,
"newStart": 109,
"newLines": 7,
"lines": [
" if ($parentId !== null) {",
" $parent = $this->find($parentId);",
" if ($parent !== null) {",
"- $depth = (int) $parent['depth'] + 1;",
"+ $depth = $parent['depth'] + 1;",
" $path = $parent['path'] . '\/' . $name;",
" }",
" }"
]
}
],
"userModified": false,
"replaceAll": true
}
}