Protokoll #5399

ID5399
Zeitstempel2025-12-22 22:18:26.256584
Clientroot
IP
Warning: Undefined array key "request_ip" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens10,045 (Input: 0, Output: 0)
Dauer98 ms
Request-Zeit
Warning: Undefined array key "request_timestamp" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 18
Response-Zeit-

Warning: Undefined array key "error_message" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 22

Request

{
    "event": "PreToolUse",
    "tool_name": "Write",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/Api\/ExplorerController.php",
        "content": "<?php\n\nnamespace Controller\\Api;\n\nuse Framework\\Controller;\nuse Infrastructure\\Docs\\HybridSearchService;\nuse Infrastructure\\Persistence\\SystemExplorerRepository;\nuse Infrastructure\\Traits\\JsonDecodeTrait;\n\n\/**\n * ExplorerController - REST-API für Doc2Vector Pipeline\n *\n * Endpoints für Dokumente, Seiten, Chunks, Taxonomie und Suche.\n *\/\nclass ExplorerController extends Controller\n{\n    use JsonDecodeTrait;\n\n    private SystemExplorerRepository $repository;\n\n    public function __construct()\n    {\n        $this->repository = new SystemExplorerRepository();\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/stats\n     *\/\n    public function stats(): void\n    {\n        try {\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'dokumente' => $this->repository->countDokumente(),\n                    'seiten' => $this->repository->countSeiten(),\n                    'chunks' => $this->repository->getChunkStats(),\n                    'taxonomy_categories' => $this->repository->getTopTaxonomyCategories(100),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/dokumente\n     *\/\n    public function listDokumente(): void\n    {\n        try {\n            $dokumente = $this->repository->getDokumenteWithFullStats();\n\n            $this->json([\n                'success' => true,\n                'data' => $dokumente,\n                'meta' => ['total' => count($dokumente)],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/dokumente\/{id}\n     *\/\n    public function getDokument(string $id): void\n    {\n        try {\n            $dokument = $this->repository->getDokumentRoot((int) $id);\n\n            if ($dokument === null) {\n                $this->json(['success' => false, 'error' => 'Dokument nicht gefunden'], 404);\n\n                return;\n            }\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'dokument' => $dokument,\n                    'seiten' => $this->repository->getSeitenWithStatsForParent((int) $id),\n                    'taxonomy' => $this->repository->getTaxonomyForDokumentTree((int) $id),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/seiten\n     *\/\n    public function listSeiten(): void\n    {\n        try {\n            $search = $this->getString('search');\n            $parentId = $this->getString('parent_id');\n            $limit = $this->getLimit(100, 50);\n            $offset = $this->getInt('offset');\n\n            $total = $this->repository->countSeitenFiltered($search, $parentId);\n            $seiten = $this->repository->getSeitenPaginated($search, $parentId, $limit, $offset);\n\n            $this->json([\n                'success' => true,\n                'data' => $seiten,\n                'meta' => [\n                    'total' => $total,\n                    'limit' => $limit,\n                    'offset' => $offset,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/seiten\/{id}\n     *\/\n    public function getSeite(string $id): void\n    {\n        try {\n            $seite = $this->repository->getSeiteWithParent((int) $id);\n\n            if ($seite === null) {\n                $this->json(['success' => false, 'error' => 'Seite nicht gefunden'], 404);\n\n                return;\n            }\n\n            $chunks = $this->repository->getChunksDetailedForDokument((int) $id);\n\n            \/\/ Decode JSON fields in chunks\n            foreach ($chunks as &$c) {\n                $c['entities'] = $this->decodeJsonArray($c['entities'] ?? null);\n                $c['keywords'] = $this->decodeJsonArray($c['keywords'] ?? null);\n                $c['taxonomy_path'] = $this->decodeJsonArray($c['taxonomy_path'] ?? null);\n            }\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'seite' => $seite,\n                    'chunks' => $chunks,\n                    'unterseiten' => $this->repository->getUnterseiten((int) $id),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/chunks\n     *\/\n    public function listChunks(): void\n    {\n        try {\n            $category = $this->getString('category');\n            $status = $this->getString('status');\n            $search = $this->getString('search');\n            $limit = $this->getLimit(100, 50);\n            $offset = $this->getInt('offset');\n\n            $total = $this->repository->countChunksFiltered($category, $status, $search);\n            $chunks = $this->repository->getChunksFilteredPaginated($category, $status, $search, $limit, $offset);\n\n            $this->json([\n                'success' => true,\n                'data' => $chunks,\n                'meta' => [\n                    'total' => $total,\n                    'limit' => $limit,\n                    'offset' => $offset,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/chunks\/{id}\n     *\/\n    public function getChunk(string $id): void\n    {\n        try {\n            $chunk = $this->repository->getChunk((int) $id);\n\n            if ($chunk === null) {\n                $this->json(['success' => false, 'error' => 'Chunk nicht gefunden'], 404);\n\n                return;\n            }\n\n            $this->json([\n                'success' => true,\n                'data' => $chunk,\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/taxonomie\n     *\/\n    public function taxonomie(): void\n    {\n        try {\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'categories' => $this->repository->getTopTaxonomyCategories(100),\n                    'top_keywords' => $this->repository->getTopKeywords(50),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/entities\n     *\/\n    public function entities(): void\n    {\n        try {\n            $this->json([\n                'success' => true,\n                'data' => $this->repository->getEntitiesGrouped(100),\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * POST \/api\/v1\/explorer\/suche\n     *\/\n    public function suche(): void\n    {\n        try {\n            $input = $this->getJsonInput();\n\n            $query = trim($input['query'] ?? '');\n            if ($query === '') {\n                $this->json(['success' => false, 'error' => 'Query ist erforderlich'], 400);\n\n                return;\n            }\n\n            $filters = [];\n            if (!empty($input['category'])) {\n                $filters['taxonomy_category'] = $input['category'];\n            }\n\n            $limit = min((int) ($input['limit'] ?? 10), 50);\n\n            $search = new HybridSearchService();\n            $results = $search->search($query, $filters, $limit);\n            $suggestions = $search->suggestRelatedSearches($results);\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'query' => $query,\n                    'results' => $results,\n                    'suggestions' => $suggestions,\n                    'count' => count($results),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n}\n"
    }
}

Response

{
    "tool_response": {
        "type": "update",
        "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/Api\/ExplorerController.php",
        "content": "<?php\n\nnamespace Controller\\Api;\n\nuse Framework\\Controller;\nuse Infrastructure\\Docs\\HybridSearchService;\nuse Infrastructure\\Persistence\\SystemExplorerRepository;\nuse Infrastructure\\Traits\\JsonDecodeTrait;\n\n\/**\n * ExplorerController - REST-API für Doc2Vector Pipeline\n *\n * Endpoints für Dokumente, Seiten, Chunks, Taxonomie und Suche.\n *\/\nclass ExplorerController extends Controller\n{\n    use JsonDecodeTrait;\n\n    private SystemExplorerRepository $repository;\n\n    public function __construct()\n    {\n        $this->repository = new SystemExplorerRepository();\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/stats\n     *\/\n    public function stats(): void\n    {\n        try {\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'dokumente' => $this->repository->countDokumente(),\n                    'seiten' => $this->repository->countSeiten(),\n                    'chunks' => $this->repository->getChunkStats(),\n                    'taxonomy_categories' => $this->repository->getTopTaxonomyCategories(100),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/dokumente\n     *\/\n    public function listDokumente(): void\n    {\n        try {\n            $dokumente = $this->repository->getDokumenteWithFullStats();\n\n            $this->json([\n                'success' => true,\n                'data' => $dokumente,\n                'meta' => ['total' => count($dokumente)],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/dokumente\/{id}\n     *\/\n    public function getDokument(string $id): void\n    {\n        try {\n            $dokument = $this->repository->getDokumentRoot((int) $id);\n\n            if ($dokument === null) {\n                $this->json(['success' => false, 'error' => 'Dokument nicht gefunden'], 404);\n\n                return;\n            }\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'dokument' => $dokument,\n                    'seiten' => $this->repository->getSeitenWithStatsForParent((int) $id),\n                    'taxonomy' => $this->repository->getTaxonomyForDokumentTree((int) $id),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/seiten\n     *\/\n    public function listSeiten(): void\n    {\n        try {\n            $search = $this->getString('search');\n            $parentId = $this->getString('parent_id');\n            $limit = $this->getLimit(100, 50);\n            $offset = $this->getInt('offset');\n\n            $total = $this->repository->countSeitenFiltered($search, $parentId);\n            $seiten = $this->repository->getSeitenPaginated($search, $parentId, $limit, $offset);\n\n            $this->json([\n                'success' => true,\n                'data' => $seiten,\n                'meta' => [\n                    'total' => $total,\n                    'limit' => $limit,\n                    'offset' => $offset,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/seiten\/{id}\n     *\/\n    public function getSeite(string $id): void\n    {\n        try {\n            $seite = $this->repository->getSeiteWithParent((int) $id);\n\n            if ($seite === null) {\n                $this->json(['success' => false, 'error' => 'Seite nicht gefunden'], 404);\n\n                return;\n            }\n\n            $chunks = $this->repository->getChunksDetailedForDokument((int) $id);\n\n            \/\/ Decode JSON fields in chunks\n            foreach ($chunks as &$c) {\n                $c['entities'] = $this->decodeJsonArray($c['entities'] ?? null);\n                $c['keywords'] = $this->decodeJsonArray($c['keywords'] ?? null);\n                $c['taxonomy_path'] = $this->decodeJsonArray($c['taxonomy_path'] ?? null);\n            }\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'seite' => $seite,\n                    'chunks' => $chunks,\n                    'unterseiten' => $this->repository->getUnterseiten((int) $id),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/chunks\n     *\/\n    public function listChunks(): void\n    {\n        try {\n            $category = $this->getString('category');\n            $status = $this->getString('status');\n            $search = $this->getString('search');\n            $limit = $this->getLimit(100, 50);\n            $offset = $this->getInt('offset');\n\n            $total = $this->repository->countChunksFiltered($category, $status, $search);\n            $chunks = $this->repository->getChunksFilteredPaginated($category, $status, $search, $limit, $offset);\n\n            $this->json([\n                'success' => true,\n                'data' => $chunks,\n                'meta' => [\n                    'total' => $total,\n                    'limit' => $limit,\n                    'offset' => $offset,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/chunks\/{id}\n     *\/\n    public function getChunk(string $id): void\n    {\n        try {\n            $chunk = $this->repository->getChunk((int) $id);\n\n            if ($chunk === null) {\n                $this->json(['success' => false, 'error' => 'Chunk nicht gefunden'], 404);\n\n                return;\n            }\n\n            $this->json([\n                'success' => true,\n                'data' => $chunk,\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/taxonomie\n     *\/\n    public function taxonomie(): void\n    {\n        try {\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'categories' => $this->repository->getTopTaxonomyCategories(100),\n                    'top_keywords' => $this->repository->getTopKeywords(50),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/entities\n     *\/\n    public function entities(): void\n    {\n        try {\n            $this->json([\n                'success' => true,\n                'data' => $this->repository->getEntitiesGrouped(100),\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * POST \/api\/v1\/explorer\/suche\n     *\/\n    public function suche(): void\n    {\n        try {\n            $input = $this->getJsonInput();\n\n            $query = trim($input['query'] ?? '');\n            if ($query === '') {\n                $this->json(['success' => false, 'error' => 'Query ist erforderlich'], 400);\n\n                return;\n            }\n\n            $filters = [];\n            if (!empty($input['category'])) {\n                $filters['taxonomy_category'] = $input['category'];\n            }\n\n            $limit = min((int) ($input['limit'] ?? 10), 50);\n\n            $search = new HybridSearchService();\n            $results = $search->search($query, $filters, $limit);\n            $suggestions = $search->suggestRelatedSearches($results);\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'query' => $query,\n                    'results' => $results,\n                    'suggestions' => $suggestions,\n                    'count' => count($results),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n}\n",
        "structuredPatch": [
            {
                "oldStart": 3,
                "oldLines": 24,
                "newStart": 3,
                "newLines": 23,
                "lines": [
                    " namespace Controller\\Api;",
                    " ",
                    " use Framework\\Controller;",
                    "-use Infrastructure\\Config\\DatabaseFactory;",
                    " use Infrastructure\\Docs\\HybridSearchService;",
                    " use Infrastructure\\Persistence\\SystemExplorerRepository;",
                    "+use Infrastructure\\Traits\\JsonDecodeTrait;",
                    " ",
                    " \/**",
                    "  * ExplorerController - REST-API für Doc2Vector Pipeline",
                    "  *",
                    "  * Endpoints für Dokumente, Seiten, Chunks, Taxonomie und Suche.",
                    "- * Uses ki_dev database for dokumentation tables.",
                    "  *\/",
                    " class ExplorerController extends Controller",
                    " {",
                    "-    private \\PDO $db;",
                    "+    use JsonDecodeTrait;",
                    "+",
                    "     private SystemExplorerRepository $repository;",
                    " ",
                    "     public function __construct()",
                    "     {",
                    "-        $this->db = DatabaseFactory::dev();",
                    "         $this->repository = new SystemExplorerRepository();",
                    "     }",
                    " "
                ]
            },
            {
                "oldStart": 30,
                "oldLines": 14,
                "newStart": 29,
                "newLines": 12,
                "lines": [
                    "     public function stats(): void",
                    "     {",
                    "         try {",
                    "-            $chunkStats = $this->repository->getChunkStats();",
                    "-",
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => [",
                    "                     'dokumente' => $this->repository->countDokumente(),",
                    "                     'seiten' => $this->repository->countSeiten(),",
                    "-                    'chunks' => $chunkStats,",
                    "+                    'chunks' => $this->repository->getChunkStats(),",
                    "                     'taxonomy_categories' => $this->repository->getTopTaxonomyCategories(100),",
                    "                 ],",
                    "             ]);"
                ]
            },
            {
                "oldStart": 57,
                "oldLines": 9,
                "newStart": 54,
                "newLines": 7,
                "lines": [
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => $dokumente,",
                    "-                'meta' => [",
                    "-                    'total' => count($dokumente),",
                    "-                ],",
                    "+                'meta' => ['total' => count($dokumente)],",
                    "             ]);",
                    "         } catch (\\Exception $e) {",
                    "             $this->jsonError($e->getMessage());"
                ]
            },
            {
                "oldStart": 72,
                "oldLines": 50,
                "newStart": 67,
                "newLines": 20,
                "lines": [
                    "     public function getDokument(string $id): void",
                    "     {",
                    "         try {",
                    "-            $stmt = $this->db->prepare(",
                    "-                'SELECT * FROM dokumentation WHERE id = :id AND depth = 0'",
                    "-            );",
                    "-            $stmt->execute(['id' => (int) $id]);",
                    "-            $dokument = $stmt->fetch();",
                    "+            $dokument = $this->repository->getDokumentRoot((int) $id);",
                    " ",
                    "-            if ($dokument === false) {",
                    "+            if ($dokument === null) {",
                    "                 $this->json(['success' => false, 'error' => 'Dokument nicht gefunden'], 404);",
                    " ",
                    "                 return;",
                    "             }",
                    " ",
                    "-            \/\/ Seiten",
                    "-            $stmt = $this->db->prepare(",
                    "-                'SELECT s.id, s.title, s.path, s.depth,",
                    "-                        (SELECT COUNT(*) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as chunks_count,",
                    "-                        (SELECT COALESCE(SUM(token_count), 0) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as token_count",
                    "-                 FROM dokumentation s",
                    "-                 WHERE s.parent_id = :id",
                    "-                 ORDER BY s.title'",
                    "-            );",
                    "-            $stmt->execute(['id' => (int) $id]);",
                    "-            $seiten = $stmt->fetchAll();",
                    "-",
                    "-            \/\/ Taxonomie",
                    "-            $stmt = $this->db->prepare(",
                    "-                'SELECT taxonomy_category, COUNT(*) as count",
                    "-                 FROM dokumentation_chunks",
                    "-                 WHERE dokumentation_id IN (",
                    "-                     SELECT id FROM dokumentation WHERE id = :id OR parent_id = :id2",
                    "-                 )",
                    "-                 AND taxonomy_category IS NOT NULL",
                    "-                 GROUP BY taxonomy_category",
                    "-                 ORDER BY count DESC'",
                    "-            );",
                    "-            $stmt->execute(['id' => (int) $id, 'id2' => (int) $id]);",
                    "-            $taxonomy = $stmt->fetchAll();",
                    "-",
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => [",
                    "                     'dokument' => $dokument,",
                    "-                    'seiten' => $seiten,",
                    "-                    'taxonomy' => $taxonomy,",
                    "+                    'seiten' => $this->repository->getSeitenWithStatsForParent((int) $id),",
                    "+                    'taxonomy' => $this->repository->getTaxonomyForDokumentTree((int) $id),",
                    "                 ],",
                    "             ]);",
                    "         } catch (\\Exception $e) {"
                ]
            },
            {
                "oldStart": 134,
                "oldLines": 45,
                "newStart": 99,
                "newLines": 9,
                "lines": [
                    "             $limit = $this->getLimit(100, 50);",
                    "             $offset = $this->getInt('offset');",
                    " ",
                    "-            $sql = 'SELECT s.id, s.title, s.path, s.depth, s.parent_id,",
                    "-                           p.title as parent_title,",
                    "-                           (SELECT COUNT(*) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as chunks_count,",
                    "-                           (SELECT COALESCE(SUM(token_count), 0) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as token_count",
                    "-                    FROM dokumentation s",
                    "-                    LEFT JOIN dokumentation p ON s.parent_id = p.id",
                    "-                    WHERE s.depth > 0';",
                    "+            $total = $this->repository->countSeitenFiltered($search, $parentId);",
                    "+            $seiten = $this->repository->getSeitenPaginated($search, $parentId, $limit, $offset);",
                    " ",
                    "-            $countSql = 'SELECT COUNT(*) FROM dokumentation s WHERE s.depth > 0';",
                    "-            $params = [];",
                    "-",
                    "-            if ($search !== '') {",
                    "-                $sql .= ' AND (s.title LIKE :search OR s.path LIKE :search2)';",
                    "-                $countSql .= ' AND (s.title LIKE :search OR s.path LIKE :search2)';",
                    "-                $params['search'] = '%' . $search . '%';",
                    "-                $params['search2'] = '%' . $search . '%';",
                    "-            }",
                    "-",
                    "-            if ($parentId !== '') {",
                    "-                $sql .= ' AND s.parent_id = :parent';",
                    "-                $countSql .= ' AND s.parent_id = :parent';",
                    "-                $params['parent'] = (int) $parentId;",
                    "-            }",
                    "-",
                    "-            $stmt = $this->db->prepare($countSql);",
                    "-            $stmt->execute($params);",
                    "-            $total = (int) $stmt->fetchColumn();",
                    "-",
                    "-            $sql .= ' ORDER BY p.title, s.depth, s.title LIMIT :limit OFFSET :offset';",
                    "-            $params['limit'] = $limit;",
                    "-            $params['offset'] = $offset;",
                    "-",
                    "-            $stmt = $this->db->prepare($sql);",
                    "-            foreach ($params as $key => $value) {",
                    "-                $stmt->bindValue($key, $value, is_int($value) ? \\PDO::PARAM_INT : \\PDO::PARAM_STR);",
                    "-            }",
                    "-            $stmt->execute();",
                    "-            $seiten = $stmt->fetchAll();",
                    "-",
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => $seiten,"
                ]
            },
            {
                "oldStart": 193,
                "oldLines": 52,
                "newStart": 122,
                "newLines": 29,
                "lines": [
                    "     public function getSeite(string $id): void",
                    "     {",
                    "         try {",
                    "-            $stmt = $this->db->prepare(",
                    "-                'SELECT s.*, p.title as parent_title, p.path as parent_path",
                    "-                 FROM dokumentation s",
                    "-                 LEFT JOIN dokumentation p ON s.parent_id = p.id",
                    "-                 WHERE s.id = :id'",
                    "-            );",
                    "-            $stmt->execute(['id' => (int) $id]);",
                    "-            $seite = $stmt->fetch();",
                    "+            $seite = $this->repository->getSeiteWithParent((int) $id);",
                    " ",
                    "-            if ($seite === false) {",
                    "+            if ($seite === null) {",
                    "                 $this->json(['success' => false, 'error' => 'Seite nicht gefunden'], 404);",
                    " ",
                    "                 return;",
                    "             }",
                    " ",
                    "-            \/\/ Chunks",
                    "-            $stmt = $this->db->prepare(",
                    "-                'SELECT c.id, c.chunk_index, c.content, c.token_count, c.taxonomy_category,",
                    "-                        c.taxonomy_path, c.entities, c.keywords, c.analysis_status, c.qdrant_id",
                    "-                 FROM dokumentation_chunks c",
                    "-                 WHERE c.dokumentation_id = :id",
                    "-                 ORDER BY c.chunk_index'",
                    "-            );",
                    "-            $stmt->execute(['id' => (int) $id]);",
                    "-            $chunks = $stmt->fetchAll();",
                    "+            $chunks = $this->repository->getChunksDetailedForDokument((int) $id);",
                    " ",
                    "-            \/\/ Decode JSON",
                    "+            \/\/ Decode JSON fields in chunks",
                    "             foreach ($chunks as &$c) {",
                    "-                $c['entities'] = $this->decodeJson($c['entities'] ?? null);",
                    "-                $c['keywords'] = $this->decodeJson($c['keywords'] ?? null);",
                    "-                $c['taxonomy_path'] = $this->decodeJson($c['taxonomy_path'] ?? null);",
                    "+                $c['entities'] = $this->decodeJsonArray($c['entities'] ?? null);",
                    "+                $c['keywords'] = $this->decodeJsonArray($c['keywords'] ?? null);",
                    "+                $c['taxonomy_path'] = $this->decodeJsonArray($c['taxonomy_path'] ?? null);",
                    "             }",
                    " ",
                    "-            \/\/ Unterseiten",
                    "-            $stmt = $this->db->prepare(",
                    "-                'SELECT id, title, path, depth FROM dokumentation WHERE parent_id = :id ORDER BY title'",
                    "-            );",
                    "-            $stmt->execute(['id' => (int) $id]);",
                    "-            $unterseiten = $stmt->fetchAll();",
                    "-",
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => [",
                    "                     'seite' => $seite,",
                    "                     'chunks' => $chunks,",
                    "-                    'unterseiten' => $unterseiten,",
                    "+                    'unterseiten' => $this->repository->getUnterseiten((int) $id),",
                    "                 ],",
                    "             ]);",
                    "         } catch (\\Exception $e) {"
                ]
            },
            {
                "oldStart": 258,
                "oldLines": 50,
                "newStart": 164,
                "newLines": 9,
                "lines": [
                    "             $limit = $this->getLimit(100, 50);",
                    "             $offset = $this->getInt('offset');",
                    " ",
                    "-            $sql = 'SELECT c.id, c.chunk_index, c.content, c.token_count, c.taxonomy_category,",
                    "-                           c.analysis_status, c.qdrant_id, c.created_at,",
                    "-                           d.id as dokumentation_id, d.title as dokument_title, d.path as dokument_path",
                    "-                    FROM dokumentation_chunks c",
                    "-                    JOIN dokumentation d ON c.dokumentation_id = d.id",
                    "-                    WHERE 1=1';",
                    "+            $total = $this->repository->countChunksFiltered($category, $status, $search);",
                    "+            $chunks = $this->repository->getChunksFilteredPaginated($category, $status, $search, $limit, $offset);",
                    " ",
                    "-            $countSql = 'SELECT COUNT(*) FROM dokumentation_chunks c WHERE 1=1';",
                    "-            $params = [];",
                    "-",
                    "-            if ($category !== '') {",
                    "-                $sql .= ' AND c.taxonomy_category = :category';",
                    "-                $countSql .= ' AND c.taxonomy_category = :category';",
                    "-                $params['category'] = $category;",
                    "-            }",
                    "-",
                    "-            if ($status !== '') {",
                    "-                $sql .= ' AND c.analysis_status = :status';",
                    "-                $countSql .= ' AND c.analysis_status = :status';",
                    "-                $params['status'] = $status;",
                    "-            }",
                    "-",
                    "-            if ($search !== '') {",
                    "-                $sql .= ' AND (c.content LIKE :search OR c.keywords LIKE :search2)';",
                    "-                $countSql .= ' AND (c.content LIKE :search OR c.keywords LIKE :search2)';",
                    "-                $params['search'] = '%' . $search . '%';",
                    "-                $params['search2'] = '%' . $search . '%';",
                    "-            }",
                    "-",
                    "-            $stmt = $this->db->prepare($countSql);",
                    "-            $stmt->execute($params);",
                    "-            $total = (int) $stmt->fetchColumn();",
                    "-",
                    "-            $sql .= ' ORDER BY c.created_at DESC LIMIT :limit OFFSET :offset';",
                    "-            $params['limit'] = $limit;",
                    "-            $params['offset'] = $offset;",
                    "-",
                    "-            $stmt = $this->db->prepare($sql);",
                    "-            foreach ($params as $key => $value) {",
                    "-                $stmt->bindValue($key, $value, is_int($value) ? \\PDO::PARAM_INT : \\PDO::PARAM_STR);",
                    "-            }",
                    "-            $stmt->execute();",
                    "-            $chunks = $stmt->fetchAll();",
                    "-",
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => $chunks,"
                ]
            },
            {
                "oldStart": 330,
                "oldLines": 7,
                "newStart": 195,
                "newLines": 6,
                "lines": [
                    "                 return;",
                    "             }",
                    " ",
                    "-            \/\/ Repository liefert bereits dekodierte JSON-Felder",
                    "             $this->json([",
                    "                 'success' => true,",
                    "                 'data' => $chunk,"
                ]
            }
        ],
        "originalFile": "<?php\n\nnamespace Controller\\Api;\n\nuse Framework\\Controller;\nuse Infrastructure\\Config\\DatabaseFactory;\nuse Infrastructure\\Docs\\HybridSearchService;\nuse Infrastructure\\Persistence\\SystemExplorerRepository;\n\n\/**\n * ExplorerController - REST-API für Doc2Vector Pipeline\n *\n * Endpoints für Dokumente, Seiten, Chunks, Taxonomie und Suche.\n * Uses ki_dev database for dokumentation tables.\n *\/\nclass ExplorerController extends Controller\n{\n    private \\PDO $db;\n    private SystemExplorerRepository $repository;\n\n    public function __construct()\n    {\n        $this->db = DatabaseFactory::dev();\n        $this->repository = new SystemExplorerRepository();\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/stats\n     *\/\n    public function stats(): void\n    {\n        try {\n            $chunkStats = $this->repository->getChunkStats();\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'dokumente' => $this->repository->countDokumente(),\n                    'seiten' => $this->repository->countSeiten(),\n                    'chunks' => $chunkStats,\n                    'taxonomy_categories' => $this->repository->getTopTaxonomyCategories(100),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/dokumente\n     *\/\n    public function listDokumente(): void\n    {\n        try {\n            $dokumente = $this->repository->getDokumenteWithFullStats();\n\n            $this->json([\n                'success' => true,\n                'data' => $dokumente,\n                'meta' => [\n                    'total' => count($dokumente),\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/dokumente\/{id}\n     *\/\n    public function getDokument(string $id): void\n    {\n        try {\n            $stmt = $this->db->prepare(\n                'SELECT * FROM dokumentation WHERE id = :id AND depth = 0'\n            );\n            $stmt->execute(['id' => (int) $id]);\n            $dokument = $stmt->fetch();\n\n            if ($dokument === false) {\n                $this->json(['success' => false, 'error' => 'Dokument nicht gefunden'], 404);\n\n                return;\n            }\n\n            \/\/ Seiten\n            $stmt = $this->db->prepare(\n                'SELECT s.id, s.title, s.path, s.depth,\n                        (SELECT COUNT(*) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as chunks_count,\n                        (SELECT COALESCE(SUM(token_count), 0) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as token_count\n                 FROM dokumentation s\n                 WHERE s.parent_id = :id\n                 ORDER BY s.title'\n            );\n            $stmt->execute(['id' => (int) $id]);\n            $seiten = $stmt->fetchAll();\n\n            \/\/ Taxonomie\n            $stmt = $this->db->prepare(\n                'SELECT taxonomy_category, COUNT(*) as count\n                 FROM dokumentation_chunks\n                 WHERE dokumentation_id IN (\n                     SELECT id FROM dokumentation WHERE id = :id OR parent_id = :id2\n                 )\n                 AND taxonomy_category IS NOT NULL\n                 GROUP BY taxonomy_category\n                 ORDER BY count DESC'\n            );\n            $stmt->execute(['id' => (int) $id, 'id2' => (int) $id]);\n            $taxonomy = $stmt->fetchAll();\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'dokument' => $dokument,\n                    'seiten' => $seiten,\n                    'taxonomy' => $taxonomy,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/seiten\n     *\/\n    public function listSeiten(): void\n    {\n        try {\n            $search = $this->getString('search');\n            $parentId = $this->getString('parent_id');\n            $limit = $this->getLimit(100, 50);\n            $offset = $this->getInt('offset');\n\n            $sql = 'SELECT s.id, s.title, s.path, s.depth, s.parent_id,\n                           p.title as parent_title,\n                           (SELECT COUNT(*) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as chunks_count,\n                           (SELECT COALESCE(SUM(token_count), 0) FROM dokumentation_chunks WHERE dokumentation_id = s.id) as token_count\n                    FROM dokumentation s\n                    LEFT JOIN dokumentation p ON s.parent_id = p.id\n                    WHERE s.depth > 0';\n\n            $countSql = 'SELECT COUNT(*) FROM dokumentation s WHERE s.depth > 0';\n            $params = [];\n\n            if ($search !== '') {\n                $sql .= ' AND (s.title LIKE :search OR s.path LIKE :search2)';\n                $countSql .= ' AND (s.title LIKE :search OR s.path LIKE :search2)';\n                $params['search'] = '%' . $search . '%';\n                $params['search2'] = '%' . $search . '%';\n            }\n\n            if ($parentId !== '') {\n                $sql .= ' AND s.parent_id = :parent';\n                $countSql .= ' AND s.parent_id = :parent';\n                $params['parent'] = (int) $parentId;\n            }\n\n            $stmt = $this->db->prepare($countSql);\n            $stmt->execute($params);\n            $total = (int) $stmt->fetchColumn();\n\n            $sql .= ' ORDER BY p.title, s.depth, s.title LIMIT :limit OFFSET :offset';\n            $params['limit'] = $limit;\n            $params['offset'] = $offset;\n\n            $stmt = $this->db->prepare($sql);\n            foreach ($params as $key => $value) {\n                $stmt->bindValue($key, $value, is_int($value) ? \\PDO::PARAM_INT : \\PDO::PARAM_STR);\n            }\n            $stmt->execute();\n            $seiten = $stmt->fetchAll();\n\n            $this->json([\n                'success' => true,\n                'data' => $seiten,\n                'meta' => [\n                    'total' => $total,\n                    'limit' => $limit,\n                    'offset' => $offset,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/seiten\/{id}\n     *\/\n    public function getSeite(string $id): void\n    {\n        try {\n            $stmt = $this->db->prepare(\n                'SELECT s.*, p.title as parent_title, p.path as parent_path\n                 FROM dokumentation s\n                 LEFT JOIN dokumentation p ON s.parent_id = p.id\n                 WHERE s.id = :id'\n            );\n            $stmt->execute(['id' => (int) $id]);\n            $seite = $stmt->fetch();\n\n            if ($seite === false) {\n                $this->json(['success' => false, 'error' => 'Seite nicht gefunden'], 404);\n\n                return;\n            }\n\n            \/\/ Chunks\n            $stmt = $this->db->prepare(\n                'SELECT c.id, c.chunk_index, c.content, c.token_count, c.taxonomy_category,\n                        c.taxonomy_path, c.entities, c.keywords, c.analysis_status, c.qdrant_id\n                 FROM dokumentation_chunks c\n                 WHERE c.dokumentation_id = :id\n                 ORDER BY c.chunk_index'\n            );\n            $stmt->execute(['id' => (int) $id]);\n            $chunks = $stmt->fetchAll();\n\n            \/\/ Decode JSON\n            foreach ($chunks as &$c) {\n                $c['entities'] = $this->decodeJson($c['entities'] ?? null);\n                $c['keywords'] = $this->decodeJson($c['keywords'] ?? null);\n                $c['taxonomy_path'] = $this->decodeJson($c['taxonomy_path'] ?? null);\n            }\n\n            \/\/ Unterseiten\n            $stmt = $this->db->prepare(\n                'SELECT id, title, path, depth FROM dokumentation WHERE parent_id = :id ORDER BY title'\n            );\n            $stmt->execute(['id' => (int) $id]);\n            $unterseiten = $stmt->fetchAll();\n\n            $this->json([\n                'success' => true,\n                'data' => [\n                    'seite' => $seite,\n                    'chunks' => $chunks,\n                    'unterseiten' => $unterseiten,\n                ],\n            ]);\n        } catch (\\Exception $e) {\n            $this->jsonError($e->getMessage());\n        }\n    }\n\n    \/**\n     * GET \/api\/v1\/explorer\/chunks\n     *\/\n    public function listChunks(): void\n    {\n        try {\n            $category = $this->getString('category');\n            $status = $this->getString('status');\n            $search = $this->getString('search');\n            $limit = $this->getLimit(100, 50);\n            $offset = $this->getInt('offset');\n\n            $sql = 'SELECT c.id, c.chunk_index, c.content, c.token_count, c.taxonomy_category,\n                           c.analysis_status, c.qdrant_id, c.created_at,\n                           d.id as dokumentation_id, d.title as dokument_title, d.path as dokument_path\n                    FROM dokumentation_chunks c\n                    JOIN dokumentation d ON c.dokumentation_id = d.id\n                    WHERE 1=1';\n\n            $countSql = 'SELECT COUNT(*) FROM dokumentation_chunks c WHERE 1=1';\n            $params = [];\n\n            if ($category !== '') {\n                $sql .= ' AND c.taxonomy_category = :category';\n                $countSql .= ' AND c.taxonomy_category = :category';\n                $params['category'] = $category;\n            }\n\n            if ($status !== '') {\n                $sql .= ' AND c.analysis_status = :status';\n                $countSql .= ' AND c.analysis_status = :status';\n                $params['status'] = $status;\n            }\n\n            if ($search !== '') {\n                $sql .= ' AND (c.content LIKE :search OR c.keywords LIKE :search2)';\n                $countSql .= ' AND (c.content LIKE :search OR c.keywords LIKE :search2)';\n                $params['search... [TRUNCATED-cea02f4293552784]"
    }
}
← Vorheriger Zur Liste Nächster →