Protokoll #3937
| ID | 3937 |
|---|---|
| Zeitstempel | 2025-12-22 08:50:34.061390 |
| Client | root |
| 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 |
| Modell | claude-sonnet-4-20250514 |
| Status | completed |
| Tokens | 3,161 (Input: 0, Output: 0) |
| Dauer | 96 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": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/ContractRepository.php",
"old_string": " \/\/ Basis-Prüfungen\n if (!isset($data['contract'])) {\n $major++;\n $violations[] = ['type' => 'major', 'message' => 'Missing contract root element'];\n }\n\n if (!isset($data['contract']['name'])) {\n $minor++;\n $violations[] = ['type' => 'minor', 'message' => 'Missing contract name'];\n }\n\n if ($critical > 0) {\n $result = 'failed';\n }",
"new_string": " \/\/ Basis-Prüfungen\n if (!isset($data['contract'])) {\n $critical++;\n $violations[] = ['type' => 'critical', 'message' => 'Missing contract root element'];\n } elseif (!isset($data['contract']['name'])) {\n $minor++;\n $violations[] = ['type' => 'minor', 'message' => 'Missing contract name'];\n }\n\n if ($critical > 0 || $major > 0) {\n $result = 'failed';\n }"
}
}
Response
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/ContractRepository.php",
"oldString": " \/\/ Basis-Prüfungen\n if (!isset($data['contract'])) {\n $major++;\n $violations[] = ['type' => 'major', 'message' => 'Missing contract root element'];\n }\n\n if (!isset($data['contract']['name'])) {\n $minor++;\n $violations[] = ['type' => 'minor', 'message' => 'Missing contract name'];\n }\n\n if ($critical > 0) {\n $result = 'failed';\n }",
"newString": " \/\/ Basis-Prüfungen\n if (!isset($data['contract'])) {\n $critical++;\n $violations[] = ['type' => 'critical', 'message' => 'Missing contract root element'];\n } elseif (!isset($data['contract']['name'])) {\n $minor++;\n $violations[] = ['type' => 'minor', 'message' => 'Missing contract name'];\n }\n\n if ($critical > 0 || $major > 0) {\n $result = 'failed';\n }",
"originalFile": "<?php\n\nnamespace Infrastructure\\Persistence;\n\nuse PDO;\n\nclass ContractRepository\n{\n private PDO $pdo;\n\n public function __construct()\n {\n \/\/ Contracts sind in ki_dev Datenbank\n $this->pdo = new PDO(\n 'mysql:host=' . KI_DEV_DB_HOST . ';dbname=' . KI_DEV_DB_NAME . ';charset=utf8mb4',\n KI_DEV_DB_USER,\n KI_DEV_DB_PASS,\n [\n PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,\n PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,\n ]\n );\n }\n\n public function findAll(array $filters = [], int $limit = 50): array\n {\n $sql = 'SELECT * FROM contracts WHERE 1=1';\n $params = [];\n\n if (isset($filters['status']) && $filters['status'] !== '') {\n $sql .= ' AND status = :status';\n $params['status'] = $filters['status'];\n }\n\n if (isset($filters['search']) && $filters['search'] !== '') {\n $sql .= ' AND (name LIKE :search OR scope_description LIKE :search2)';\n $params['search'] = '%' . $filters['search'] . '%';\n $params['search2'] = '%' . $filters['search'] . '%';\n }\n\n $sql .= ' ORDER BY name ASC, version DESC LIMIT :limit';\n\n $stmt = $this->pdo->prepare($sql);\n foreach ($params as $key => $value) {\n $stmt->bindValue(':' . $key, $value);\n }\n $stmt->bindValue(':limit', $limit, PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll(PDO::FETCH_ASSOC);\n }\n\n public function findById(int $id): ?array\n {\n $stmt = $this->pdo->prepare('SELECT * FROM contracts WHERE id = :id');\n $stmt->execute(['id' => $id]);\n $result = $stmt->fetch(PDO::FETCH_ASSOC);\n\n return $result ?: null;\n }\n\n public function findByName(string $name, ?string $version = null): ?array\n {\n if ($version !== null) {\n $stmt = $this->pdo->prepare(\n 'SELECT * FROM contracts WHERE name = :name AND version = :version'\n );\n $stmt->execute(['name' => $name, 'version' => $version]);\n } else {\n $stmt = $this->pdo->prepare(\n \"SELECT * FROM contracts WHERE name = :name AND status = 'active' ORDER BY version DESC LIMIT 1\"\n );\n $stmt->execute(['name' => $name]);\n }\n\n $result = $stmt->fetch(PDO::FETCH_ASSOC);\n\n return $result ?: null;\n }\n\n public function create(array $data): int\n {\n $stmt = $this->pdo->prepare('\n INSERT INTO contracts (uuid, name, version, status, yaml_content, scope_description, created_by)\n VALUES (UUID(), :name, :version, :status, :yaml_content, :scope_description, :created_by)\n ');\n\n $stmt->execute([\n 'name' => $data['name'],\n 'version' => $data['version'] ?? '1.0',\n 'status' => $data['status'] ?? 'active',\n 'yaml_content' => $data['yaml_content'],\n 'scope_description' => $data['scope_description'] ?? null,\n 'created_by' => $data['created_by'] ?? 'web',\n ]);\n\n return (int) $this->pdo->lastInsertId();\n }\n\n public function createNewVersion(int $id, string $yamlContent, string $newVersion, string $changeDescription): void\n {\n $contract = $this->findById($id);\n if ($contract === null) {\n throw new \\RuntimeException(\"Contract {$id} not found\");\n }\n\n $this->pdo->beginTransaction();\n\n try {\n \/\/ Historie speichern\n $stmt = $this->pdo->prepare('\n INSERT INTO contract_history (contract_id, previous_yaml, previous_version, change_description, changed_by)\n VALUES (:contract_id, :previous_yaml, :previous_version, :change_description, :changed_by)\n ');\n $stmt->execute([\n 'contract_id' => $id,\n 'previous_yaml' => $contract['yaml_content'],\n 'previous_version' => $contract['version'],\n 'change_description' => $changeDescription,\n 'changed_by' => 'web',\n ]);\n\n \/\/ Contract aktualisieren\n $stmt = $this->pdo->prepare('\n UPDATE contracts SET yaml_content = :yaml_content, version = :version WHERE id = :id\n ');\n $stmt->execute([\n 'yaml_content' => $yamlContent,\n 'version' => $newVersion,\n 'id' => $id,\n ]);\n\n $this->pdo->commit();\n } catch (\\Exception $e) {\n $this->pdo->rollBack();\n\n throw $e;\n }\n }\n\n public function deprecate(int $id): void\n {\n $stmt = $this->pdo->prepare(\"UPDATE contracts SET status = 'deprecated' WHERE id = :id\");\n $stmt->execute(['id' => $id]);\n }\n\n public function getHistory(int $contractId): array\n {\n $stmt = $this->pdo->prepare('\n SELECT * FROM contract_history\n WHERE contract_id = :contract_id\n ORDER BY changed_at DESC\n ');\n $stmt->execute(['contract_id' => $contractId]);\n\n return $stmt->fetchAll(PDO::FETCH_ASSOC);\n }\n\n public function getValidations(int $contractId, int $limit = 10): array\n {\n $stmt = $this->pdo->prepare('\n SELECT * FROM contract_validations\n WHERE contract_id = :contract_id\n ORDER BY validated_at DESC\n LIMIT :limit\n ');\n $stmt->bindValue(':contract_id', $contractId, PDO::PARAM_INT);\n $stmt->bindValue(':limit', $limit, PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll(PDO::FETCH_ASSOC);\n }\n\n public function runValidation(int $id): array\n {\n $contract = $this->findById($id);\n if ($contract === null) {\n return ['success' => false, 'error' => 'Contract not found'];\n }\n\n \/\/ Vereinfachte Validierung - prüft ob YAML gültig ist\n $startTime = microtime(true);\n\n try {\n $data = yaml_parse($contract['yaml_content']);\n $result = 'passed';\n $critical = 0;\n $major = 0;\n $minor = 0;\n $violations = [];\n\n \/\/ Basis-Prüfungen\n if (!isset($data['contract'])) {\n $major++;\n $violations[] = ['type' => 'major', 'message' => 'Missing contract root element'];\n }\n\n if (!isset($data['contract']['name'])) {\n $minor++;\n $violations[] = ['type' => 'minor', 'message' => 'Missing contract name'];\n }\n\n if ($critical > 0) {\n $result = 'failed';\n }\n } catch (\\Exception $e) {\n $result = 'failed';\n $critical = 1;\n $major = 0;\n $minor = 0;\n $violations = [['type' => 'critical', 'message' => 'Invalid YAML: ' . $e->getMessage()]];\n }\n\n $durationMs = (int) ((microtime(true) - $startTime) * 1000);\n\n \/\/ Validierung speichern\n $stmt = $this->pdo->prepare(\"\n INSERT INTO contract_validations\n (contract_id, result, critical_count, major_count, minor_count, violations, triggered_by, duration_ms)\n VALUES (:contract_id, :result, :critical, :major, :minor, :violations, 'manual', :duration_ms)\n \");\n $stmt->execute([\n 'contract_id' => $id,\n 'result' => $result,\n 'critical' => $critical,\n 'major' => $major,\n 'minor' => $minor,\n 'violations' => json_encode($violations),\n 'duration_ms' => $durationMs,\n ]);\n\n return [\n 'success' => true,\n 'result' => $result,\n 'critical' => $critical,\n 'major' => $major,\n 'minor' => $minor,\n 'violations' => $violations,\n 'duration_ms' => $durationMs,\n ];\n }\n\n public function getStatistics(): array\n {\n $stats = [\n 'total' => 0,\n 'active' => 0,\n 'draft' => 0,\n 'deprecated' => 0,\n 'validations_total' => 0,\n 'validations_passed' => 0,\n 'validations_failed' => 0,\n ];\n\n \/\/ Contracts nach Status\n $stmt = $this->pdo->query('SELECT status, COUNT(*) as cnt FROM contracts GROUP BY status');\n foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {\n $stats[$row['status']] = (int) $row['cnt'];\n $stats['total'] += (int) $row['cnt'];\n }\n\n \/\/ Validierungen\n $stmt = $this->pdo->query('SELECT result, COUNT(*) as cnt FROM contract_validations GROUP BY result');\n foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {\n $key = 'validations_' . $row['result'];\n $stats[$key] = (int) $row['cnt'];\n $stats['validations_total'] += (int) $row['cnt'];\n }\n\n return $stats;\n }\n}\n",
"structuredPatch": [
{
"oldStart": 191,
"oldLines": 16,
"newStart": 191,
"newLines": 14,
"lines": [
" ",
" \/\/ Basis-Prüfungen",
" if (!isset($data['contract'])) {",
"- $major++;",
"- $violations[] = ['type' => 'major', 'message' => 'Missing contract root element'];",
"- }",
"-",
"- if (!isset($data['contract']['name'])) {",
"+ $critical++;",
"+ $violations[] = ['type' => 'critical', 'message' => 'Missing contract root element'];",
"+ } elseif (!isset($data['contract']['name'])) {",
" $minor++;",
" $violations[] = ['type' => 'minor', 'message' => 'Missing contract name'];",
" }",
" ",
"- if ($critical > 0) {",
"+ if ($critical > 0 || $major > 0) {",
" $result = 'failed';",
" }",
" } catch (\\Exception $e) {"
]
}
],
"userModified": false,
"replaceAll": false
}
}