{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/SemanticSearchRepository.php",
"old_string": " public function __construct()\n {\n $this->db = DatabaseFactory::content();\n }",
"new_string": " public function __construct(PDO $pdo)\n {\n $this->db = $pdo;\n }"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/SemanticSearchRepository.php",
"oldString": " public function __construct()\n {\n $this->db = DatabaseFactory::content();\n }",
"newString": " public function __construct(PDO $pdo)\n {\n $this->db = $pdo;\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\Persistence;\n\n\/\/ @responsibility: Semantik-Suche und Graph-Daten für Semantic Explorer\n\nuse Domain\\Repository\\SemanticSearchRepositoryInterface;\nuse PDO;\n\nfinal class SemanticSearchRepository implements SemanticSearchRepositoryInterface\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 getSemanticStats(): array\n {\n return $this->db->query(\n 'SELECT\n (SELECT COUNT(*) FROM entities) as entities,\n (SELECT COUNT(*) FROM entity_relations) as relations,\n (SELECT COUNT(*) FROM taxonomy_terms) as taxonomy,\n (SELECT COUNT(*) FROM ontology_classes) as ontology,\n (SELECT COUNT(*) FROM chunk_semantics) as semantics'\n )->fetch();\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function findEntitySemantics(string $search = '', string $type = '', int $limit = 50, int $offset = 0): array\n {\n $sql = 'SELECT e.id, e.name, e.type, e.description,\n ce.chunk_id, c.chunk_index, d.id as document_id, d.filename\n FROM entities e\n LEFT JOIN chunk_entities ce ON e.id = ce.entity_id\n LEFT JOIN chunks c ON ce.chunk_id = c.id\n LEFT JOIN documents d ON c.document_id = d.id\n WHERE e.description IS NOT NULL';\n\n $params = [];\n\n if ($search !== '') {\n $sql .= ' AND (e.name LIKE :search OR e.description LIKE :search2)';\n $params['search'] = '%' . $search . '%';\n $params['search2'] = '%' . $search . '%';\n }\n\n if ($type !== '') {\n $sql .= ' AND e.type = :type';\n $params['type'] = $type;\n }\n\n $sql .= ' ORDER BY e.name LIMIT ' . $limit . ' OFFSET ' . $offset;\n\n $stmt = $this->db->prepare($sql);\n $stmt->execute($params);\n\n return $stmt->fetchAll();\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function countEntitySemantics(string $search = '', string $type = ''): int\n {\n $sql = 'SELECT COUNT(DISTINCT e.id) FROM entities e WHERE e.description IS NOT NULL';\n $params = [];\n\n if ($search !== '') {\n $sql .= ' AND (e.name LIKE :search OR e.description LIKE :search2)';\n $params['search'] = '%' . $search . '%';\n $params['search2'] = '%' . $search . '%';\n }\n\n if ($type !== '') {\n $sql .= ' AND e.type = :type';\n $params['type'] = $type;\n }\n\n $stmt = $this->db->prepare($sql);\n $stmt->execute($params);\n\n return (int) $stmt->fetchColumn();\n }\n\n \/**\n * {@inheritDoc}\n *\/\n public function getGraphData(): array\n {\n \/\/ Get all entities\n $entities = $this->db->query(\n 'SELECT id, name, type FROM entities ORDER BY name'\n )->fetchAll();\n\n \/\/ Get all relations\n $relations = $this->db->query(\n 'SELECT source_entity_id, target_entity_id, relation_type, strength\n FROM entity_relations'\n )->fetchAll();\n\n \/\/ Build node index for link resolution\n $nodeIndex = [];\n $nodes = [];\n foreach ($entities as $i => $entity) {\n $nodeIndex[$entity['id']] = $i;\n $nodes[] = [\n 'id' => 'entity_' . $entity['id'],\n 'label' => $entity['name'],\n 'type' => strtoupper($entity['type'] ?? 'OTHER'),\n 'entityId' => (int) $entity['id'],\n ];\n }\n\n \/\/ Build links with index references\n $links = [];\n foreach ($relations as $relation) {\n $sourceId = $relation['source_entity_id'];\n $targetId = $relation['target_entity_id'];\n\n \/\/ Skip if entity not found\n if (!isset($nodeIndex[$sourceId]) || !isset($nodeIndex[$targetId])) {\n continue;\n }\n\n $links[] = [\n 'source' => $nodeIndex[$sourceId],\n 'target' => $nodeIndex[$targetId],\n 'type' => $relation['relation_type'],\n 'strength' => (float) ($relation['strength'] ?? 1.0),\n ];\n }\n\n \/\/ Get unique types for stats\n $entityTypes = array_unique(array_column($nodes, 'type'));\n $relationTypes = array_unique(array_column($links, 'type'));\n\n return [\n 'nodes' => $nodes,\n 'links' => $links,\n 'stats' => [\n 'nodes' => count($nodes),\n 'links' => count($links),\n 'entityTypes' => count($entityTypes),\n 'relationTypes' => count($relationTypes),\n ],\n ];\n }\n}\n",
"structuredPatch": [
{
"oldStart": 13,
"oldLines": 9,
"newStart": 13,
"newLines": 9,
"lines": [
" {",
" private PDO $db;",
" ",
"- public function __construct()",
"+ public function __construct(PDO $pdo)",
" {",
"- $this->db = DatabaseFactory::content();",
"+ $this->db = $pdo;",
" }",
" ",
" \/**"
]
}
],
"userModified": false,
"replaceAll": false
}
}