{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/KiProtokollRepository.php",
"old_string": "<?php\n\nnamespace Infrastructure\\Persistence;\n\nuse Infrastructure\\Config\\DatabaseFactory;\n\n\/**\n * Repository für KI-Protokoll Datenbank (SRP)\n *\/\nclass KiProtokollRepository\n{\n private \\PDO $pdo;\n\n public function __construct(?\\PDO $pdo = null)\n {\n $this->pdo = $pdo ?? DatabaseFactory::dev();\n }\n\n \/**\n * Letzte N Protokoll-Einträge abrufen\n *\/\n public function findLatest(int $limit = 20): array\n {\n $stmt = $this->pdo->prepare(\n 'SELECT id, timestamp, client_name, request, status, duration_ms\n FROM protokoll\n ORDER BY id DESC\n LIMIT :limit'\n );\n $stmt->bindValue(':limit', $limit, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll();\n }\n}",
"new_string": "<?php\n\nnamespace Infrastructure\\Persistence;\n\nuse Infrastructure\\Config\\DatabaseFactory;\n\nclass KiProtokollRepository\n{\n private \\PDO $pdo;\n\n public function __construct(?\\PDO $pdo = null)\n {\n $this->pdo = $pdo ?? DatabaseFactory::dev();\n }\n\n public function findById(int $id): ?array\n {\n $stmt = $this->pdo->prepare('SELECT * FROM protokoll WHERE id = ?');\n $stmt->execute([$id]);\n $result = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n return $result !== false ? $result : null;\n }\n\n public function findLatest(int $limit = 20): array\n {\n $stmt = $this->pdo->prepare(\n 'SELECT id, timestamp, client_name, request, status, duration_ms\n FROM protokoll ORDER BY id DESC LIMIT ?'\n );\n $stmt->bindValue(1, $limit, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n }\n\n public function findPaginated(\n ?string $search = null,\n ?string $status = null,\n ?string $model = null,\n int $limit = 50,\n int $offset = 0\n ): array {\n $sql = 'SELECT id, timestamp, client_name, model_name, status, tokens_total, duration_ms,\n LEFT(request, 200) as request_preview\n FROM protokoll WHERE 1=1';\n $params = [];\n\n if ($search !== null && $search !== '') {\n $sql .= ' AND (request LIKE ? OR response LIKE ? OR client_name LIKE ?)';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n }\n\n if ($status !== null && $status !== '') {\n $sql .= ' AND status = ?';\n $params[] = $status;\n }\n\n if ($model !== null && $model !== '') {\n $sql .= ' AND model_name = ?';\n $params[] = $model;\n }\n\n $sql .= ' ORDER BY timestamp DESC LIMIT ? OFFSET ?';\n\n $stmt = $this->pdo->prepare($sql);\n $paramIndex = 1;\n foreach ($params as $value) {\n $stmt->bindValue($paramIndex++, $value);\n }\n $stmt->bindValue($paramIndex++, $limit, \\PDO::PARAM_INT);\n $stmt->bindValue($paramIndex, $offset, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n }\n\n public function countFiltered(?string $search = null, ?string $status = null, ?string $model = null): int\n {\n $sql = 'SELECT COUNT(*) FROM protokoll WHERE 1=1';\n $params = [];\n\n if ($search !== null && $search !== '') {\n $sql .= ' AND (request LIKE ? OR response LIKE ? OR client_name LIKE ?)';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n }\n\n if ($status !== null && $status !== '') {\n $sql .= ' AND status = ?';\n $params[] = $status;\n }\n\n if ($model !== null && $model !== '') {\n $sql .= ' AND model_name = ?';\n $params[] = $model;\n }\n\n $stmt = $this->pdo->prepare($sql);\n $stmt->execute($params);\n\n return (int) $stmt->fetchColumn();\n }\n\n public function getStatistics(): array\n {\n $stmt = $this->pdo->query(\n 'SELECT\n COUNT(*) as total,\n SUM(CASE WHEN status = \"completed\" THEN 1 ELSE 0 END) as completed,\n SUM(CASE WHEN status = \"error\" THEN 1 ELSE 0 END) as errors,\n COALESCE(SUM(tokens_total), 0) as tokens_total,\n COALESCE(SUM(duration_ms), 0) as duration_total\n FROM protokoll'\n );\n\n return $stmt->fetch(\\PDO::FETCH_ASSOC);\n }\n\n public function getDistinctModels(): array\n {\n $stmt = $this->pdo->query(\n 'SELECT DISTINCT model_name FROM protokoll WHERE model_name IS NOT NULL ORDER BY model_name'\n );\n\n return $stmt->fetchAll(\\PDO::FETCH_COLUMN);\n }\n\n public function findPreviousId(int $id): ?int\n {\n $stmt = $this->pdo->prepare('SELECT id FROM protokoll WHERE id < ? ORDER BY id DESC LIMIT 1');\n $stmt->execute([$id]);\n $result = $stmt->fetchColumn();\n\n return $result !== false ? (int) $result : null;\n }\n\n public function findNextId(int $id): ?int\n {\n $stmt = $this->pdo->prepare('SELECT id FROM protokoll WHERE id > ? ORDER BY id ASC LIMIT 1');\n $stmt->execute([$id]);\n $result = $stmt->fetchColumn();\n\n return $result !== false ? (int) $result : null;\n }\n}"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/KiProtokollRepository.php",
"oldString": "<?php\n\nnamespace Infrastructure\\Persistence;\n\nuse Infrastructure\\Config\\DatabaseFactory;\n\n\/**\n * Repository für KI-Protokoll Datenbank (SRP)\n *\/\nclass KiProtokollRepository\n{\n private \\PDO $pdo;\n\n public function __construct(?\\PDO $pdo = null)\n {\n $this->pdo = $pdo ?? DatabaseFactory::dev();\n }\n\n \/**\n * Letzte N Protokoll-Einträge abrufen\n *\/\n public function findLatest(int $limit = 20): array\n {\n $stmt = $this->pdo->prepare(\n 'SELECT id, timestamp, client_name, request, status, duration_ms\n FROM protokoll\n ORDER BY id DESC\n LIMIT :limit'\n );\n $stmt->bindValue(':limit', $limit, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll();\n }\n}",
"newString": "<?php\n\nnamespace Infrastructure\\Persistence;\n\nuse Infrastructure\\Config\\DatabaseFactory;\n\nclass KiProtokollRepository\n{\n private \\PDO $pdo;\n\n public function __construct(?\\PDO $pdo = null)\n {\n $this->pdo = $pdo ?? DatabaseFactory::dev();\n }\n\n public function findById(int $id): ?array\n {\n $stmt = $this->pdo->prepare('SELECT * FROM protokoll WHERE id = ?');\n $stmt->execute([$id]);\n $result = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n return $result !== false ? $result : null;\n }\n\n public function findLatest(int $limit = 20): array\n {\n $stmt = $this->pdo->prepare(\n 'SELECT id, timestamp, client_name, request, status, duration_ms\n FROM protokoll ORDER BY id DESC LIMIT ?'\n );\n $stmt->bindValue(1, $limit, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n }\n\n public function findPaginated(\n ?string $search = null,\n ?string $status = null,\n ?string $model = null,\n int $limit = 50,\n int $offset = 0\n ): array {\n $sql = 'SELECT id, timestamp, client_name, model_name, status, tokens_total, duration_ms,\n LEFT(request, 200) as request_preview\n FROM protokoll WHERE 1=1';\n $params = [];\n\n if ($search !== null && $search !== '') {\n $sql .= ' AND (request LIKE ? OR response LIKE ? OR client_name LIKE ?)';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n }\n\n if ($status !== null && $status !== '') {\n $sql .= ' AND status = ?';\n $params[] = $status;\n }\n\n if ($model !== null && $model !== '') {\n $sql .= ' AND model_name = ?';\n $params[] = $model;\n }\n\n $sql .= ' ORDER BY timestamp DESC LIMIT ? OFFSET ?';\n\n $stmt = $this->pdo->prepare($sql);\n $paramIndex = 1;\n foreach ($params as $value) {\n $stmt->bindValue($paramIndex++, $value);\n }\n $stmt->bindValue($paramIndex++, $limit, \\PDO::PARAM_INT);\n $stmt->bindValue($paramIndex, $offset, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll(\\PDO::FETCH_ASSOC);\n }\n\n public function countFiltered(?string $search = null, ?string $status = null, ?string $model = null): int\n {\n $sql = 'SELECT COUNT(*) FROM protokoll WHERE 1=1';\n $params = [];\n\n if ($search !== null && $search !== '') {\n $sql .= ' AND (request LIKE ? OR response LIKE ? OR client_name LIKE ?)';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n $params[] = '%' . $search . '%';\n }\n\n if ($status !== null && $status !== '') {\n $sql .= ' AND status = ?';\n $params[] = $status;\n }\n\n if ($model !== null && $model !== '') {\n $sql .= ' AND model_name = ?';\n $params[] = $model;\n }\n\n $stmt = $this->pdo->prepare($sql);\n $stmt->execute($params);\n\n return (int) $stmt->fetchColumn();\n }\n\n public function getStatistics(): array\n {\n $stmt = $this->pdo->query(\n 'SELECT\n COUNT(*) as total,\n SUM(CASE WHEN status = \"completed\" THEN 1 ELSE 0 END) as completed,\n SUM(CASE WHEN status = \"error\" THEN 1 ELSE 0 END) as errors,\n COALESCE(SUM(tokens_total), 0) as tokens_total,\n COALESCE(SUM(duration_ms), 0) as duration_total\n FROM protokoll'\n );\n\n return $stmt->fetch(\\PDO::FETCH_ASSOC);\n }\n\n public function getDistinctModels(): array\n {\n $stmt = $this->pdo->query(\n 'SELECT DISTINCT model_name FROM protokoll WHERE model_name IS NOT NULL ORDER BY model_name'\n );\n\n return $stmt->fetchAll(\\PDO::FETCH_COLUMN);\n }\n\n public function findPreviousId(int $id): ?int\n {\n $stmt = $this->pdo->prepare('SELECT id FROM protokoll WHERE id < ? ORDER BY id DESC LIMIT 1');\n $stmt->execute([$id]);\n $result = $stmt->fetchColumn();\n\n return $result !== false ? (int) $result : null;\n }\n\n public function findNextId(int $id): ?int\n {\n $stmt = $this->pdo->prepare('SELECT id FROM protokoll WHERE id > ? ORDER BY id ASC LIMIT 1');\n $stmt->execute([$id]);\n $result = $stmt->fetchColumn();\n\n return $result !== false ? (int) $result : null;\n }\n}",
"originalFile": "<?php\n\nnamespace Infrastructure\\Persistence;\n\nuse Infrastructure\\Config\\DatabaseFactory;\n\n\/**\n * Repository für KI-Protokoll Datenbank (SRP)\n *\/\nclass KiProtokollRepository\n{\n private \\PDO $pdo;\n\n public function __construct(?\\PDO $pdo = null)\n {\n $this->pdo = $pdo ?? DatabaseFactory::dev();\n }\n\n \/**\n * Letzte N Protokoll-Einträge abrufen\n *\/\n public function findLatest(int $limit = 20): array\n {\n $stmt = $this->pdo->prepare(\n 'SELECT id, timestamp, client_name, request, status, duration_ms\n FROM protokoll\n ORDER BY id DESC\n LIMIT :limit'\n );\n $stmt->bindValue(':limit', $limit, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll();\n }\n}\n",
"structuredPatch": [
{
"oldStart": 4,
"oldLines": 9,
"newStart": 4,
"newLines": 6,
"lines": [
" ",
" use Infrastructure\\Config\\DatabaseFactory;",
" ",
"-\/**",
"- * Repository für KI-Protokoll Datenbank (SRP)",
"- *\/",
" class KiProtokollRepository",
" {",
" private \\PDO $pdo;"
]
},
{
"oldStart": 16,
"oldLines": 20,
"newStart": 13,
"newLines": 137,
"lines": [
" $this->pdo = $pdo ?? DatabaseFactory::dev();",
" }",
" ",
"- \/**",
"- * Letzte N Protokoll-Einträge abrufen",
"- *\/",
"+ public function findById(int $id): ?array",
"+ {",
"+ $stmt = $this->pdo->prepare('SELECT * FROM protokoll WHERE id = ?');",
"+ $stmt->execute([$id]);",
"+ $result = $stmt->fetch(\\PDO::FETCH_ASSOC);",
"+",
"+ return $result !== false ? $result : null;",
"+ }",
"+",
" public function findLatest(int $limit = 20): array",
" {",
" $stmt = $this->pdo->prepare(",
" 'SELECT id, timestamp, client_name, request, status, duration_ms",
"- FROM protokoll",
"- ORDER BY id DESC",
"- LIMIT :limit'",
"+ FROM protokoll ORDER BY id DESC LIMIT ?'",
" );",
"- $stmt->bindValue(':limit', $limit, \\PDO::PARAM_INT);",
"+ $stmt->bindValue(1, $limit, \\PDO::PARAM_INT);",
" $stmt->execute();",
" ",
"- return $stmt->fetchAll();",
"+ return $stmt->fetchAll(\\PDO::FETCH_ASSOC);",
" }",
"+",
"+ public function findPaginated(",
"+ ?string $search = null,",
"+ ?string $status = null,",
"+ ?string $model = null,",
"+ int $limit = 50,",
"+ int $offset = 0",
"+ ): array {",
"+ $sql = 'SELECT id, timestamp, client_name, model_name, status, tokens_total, duration_ms,",
"+ LEFT(request, 200) as request_preview",
"+ FROM protokoll WHERE 1=1';",
"+ $params = [];",
"+",
"+ if ($search !== null && $search !== '') {",
"+ $sql .= ' AND (request LIKE ? OR response LIKE ? OR client_name LIKE ?)';",
"+ $params[] = '%' . $search . '%';",
"+ $params[] = '%' . $search . '%';",
"+ $params[] = '%' . $search . '%';",
"+ }",
"+",
"+ if ($status !== null && $status !== '') {",
"+ $sql .= ' AND status = ?';",
"+ $params[] = $status;",
"+ }",
"+",
"+ if ($model !== null && $model !== '') {",
"+ $sql .= ' AND model_name = ?';",
"+ $params[] = $model;",
"+ }",
"+",
"+ $sql .= ' ORDER BY timestamp DESC LIMIT ? OFFSET ?';",
"+",
"+ $stmt = $this->pdo->prepare($sql);",
"+ $paramIndex = 1;",
"+ foreach ($params as $value) {",
"+ $stmt->bindValue($paramIndex++, $value);",
"+ }",
"+ $stmt->bindValue($paramIndex++, $limit, \\PDO::PARAM_INT);",
"+ $stmt->bindValue($paramIndex, $offset, \\PDO::PARAM_INT);",
"+ $stmt->execute();",
"+",
"+ return $stmt->fetchAll(\\PDO::FETCH_ASSOC);",
"+ }",
"+",
"+ public function countFiltered(?string $search = null, ?string $status = null, ?string $model = null): int",
"+ {",
"+ $sql = 'SELECT COUNT(*) FROM protokoll WHERE 1=1';",
"+ $params = [];",
"+",
"+ if ($search !== null && $search !== '') {",
"+ $sql .= ' AND (request LIKE ? OR response LIKE ? OR client_name LIKE ?)';",
"+ $params[] = '%' . $search . '%';",
"+ $params[] = '%' . $search . '%';",
"+ $params[] = '%' . $search . '%';",
"+ }",
"+",
"+ if ($status !== null && $status !== '') {",
"+ $sql .= ' AND status = ?';",
"+ $params[] = $status;",
"+ }",
"+",
"+ if ($model !== null && $model !== '') {",
"+ $sql .= ' AND model_name = ?';",
"+ $params[] = $model;",
"+ }",
"+",
"+ $stmt = $this->pdo->prepare($sql);",
"+ $stmt->execute($params);",
"+",
"+ return (int) $stmt->fetchColumn();",
"+ }",
"+",
"+ public function getStatistics(): array",
"+ {",
"+ $stmt = $this->pdo->query(",
"+ 'SELECT",
"+ COUNT(*) as total,",
"+ SUM(CASE WHEN status = \"completed\" THEN 1 ELSE 0 END) as completed,",
"+ SUM(CASE WHEN status = \"error\" THEN 1 ELSE 0 END) as errors,",
"+ COALESCE(SUM(tokens_total), 0) as tokens_total,",
"+ COALESCE(SUM(duration_ms), 0) as duration_total",
"+ FROM protokoll'",
"+ );",
"+",
"+ return $stmt->fetch(\\PDO::FETCH_ASSOC);",
"+ }",
"+",
"+ public function getDistinctModels(): array",
"+ {",
"+ $stmt = $this->pdo->query(",
"+ 'SELECT DISTINCT model_name FROM protokoll WHERE model_name IS NOT NULL ORDER BY model_name'",
"+ );",
"+",
"+ return $stmt->fetchAll(\\PDO::FETCH_COLUMN);",
"+ }",
"+",
"+ public function findPreviousId(int $id): ?int",
"+ {",
"+ $stmt = $this->pdo->prepare('SELECT id FROM protokoll WHERE id < ? ORDER BY id DESC LIMIT 1');",
"+ $stmt->execute([$id]);",
"+ $result = $stmt->fetchColumn();",
"+",
"+ return $result !== false ? (int) $result : null;",
"+ }",
"+",
"+ public function findNextId(int $id): ?int",
"+ {",
"+ $stmt = $this->pdo->prepare('SELECT id FROM protokoll WHERE id > ? ORDER BY id ASC LIMIT 1');",
"+ $stmt->execute([$id]);",
"+ $result = $stmt->fetchColumn();",
"+",
"+ return $result !== false ? (int) $result : null;",
"+ }",
" }"
]
}
],
"userModified": false,
"replaceAll": false
}
}