{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/ContractController.php",
"oldString": " \/**\n * POST \/contracts\/{id}\n *\/\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $yamlContent = $_POST['yaml_content'] ?? '';\n $newVersion = trim($_POST['new_version'] ?? '');\n $changeDescription = trim($_POST['change_description'] ?? '');\n\n if ($yamlContent === '' || $newVersion === '') {\n $_SESSION['error'] = 'YAML-Inhalt und neue Version sind erforderlich.';\n header('Location: \/contracts\/' . $id . '\/edit');\n exit;\n }\n\n \/\/ YAML-Syntax validieren\n try {\n yaml_parse($yamlContent);\n } catch (\\Exception $e) {\n $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();\n header('Location: \/contracts\/' . $id . '\/edit');\n exit;\n }\n\n $this->repository->createNewVersion(\n (int) $id,\n $yamlContent,\n $newVersion,\n $changeDescription\n );\n\n $_SESSION['success'] = 'Contract auf Version ' . $newVersion . ' aktualisiert.';\n header('Location: \/contracts\/' . $id);\n exit;\n }",
"newString": " \/**\n * POST \/contracts\/{id}\n *\/\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $isHtmx = $this->isHtmxRequest();\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $yamlContent = $_POST['yaml_content'] ?? '';\n $newVersion = trim($_POST['new_version'] ?? '');\n $changeDescription = trim($_POST['change_description'] ?? '');\n\n if ($yamlContent === '' || $newVersion === '') {\n if ($isHtmx) {\n $this->htmxError('YAML-Inhalt und neue Version sind erforderlich.');\n\n return;\n }\n $_SESSION['error'] = 'YAML-Inhalt und neue Version sind erforderlich.';\n $this->redirect('\/contracts\/' . $id . '\/edit');\n }\n\n \/\/ YAML-Syntax validieren\n try {\n yaml_parse($yamlContent);\n } catch (\\Exception $e) {\n if ($isHtmx) {\n $this->htmxError('Ungültige YAML-Syntax: ' . $e->getMessage());\n\n return;\n }\n $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();\n $this->redirect('\/contracts\/' . $id . '\/edit');\n }\n\n $this->repository->createNewVersion(\n (int) $id,\n $yamlContent,\n $newVersion,\n $changeDescription\n );\n\n if ($isHtmx) {\n $this->htmxRedirect('\/contracts\/' . $id);\n\n return;\n }\n\n $_SESSION['success'] = 'Contract auf Version ' . $newVersion . ' aktualisiert.';\n $this->redirect('\/contracts\/' . $id);\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Controller;\n\n\/\/ @responsibility: HTTP-Endpunkte für Contract-Management (YAML-basierte Konfigurationen)\n\nuse Domain\\Repository\\ContractRepositoryInterface;\nuse Framework\\Controller;\n\nclass ContractController extends Controller\n{\n private ContractRepositoryInterface $repository;\n\n public function __construct(ContractRepositoryInterface $repository)\n {\n $this->repository = $repository;\n }\n\n \/**\n * GET \/contracts\n *\/\n public function index(): void\n {\n $filters = [];\n $status = $this->getString('status');\n if ($status !== '') {\n $filters['status'] = $status;\n }\n\n $contracts = $this->repository->findAll($filters);\n $stats = $this->repository->getStatistics();\n\n $this->view('contracts.index', [\n 'title' => 'Contracts',\n 'contracts' => $contracts,\n 'stats' => $stats,\n 'currentStatus' => $status,\n ]);\n }\n\n \/**\n * GET \/contracts\/new\n *\/\n public function contractNew(): void\n {\n $this->view('contracts.new', [\n 'title' => 'Neuer Contract',\n ]);\n }\n\n \/**\n * POST \/contracts\n *\/\n public function store(): void\n {\n $this->requireCsrf();\n\n $isHtmx = $this->isHtmxRequest();\n $name = trim($_POST['name'] ?? '');\n $version = trim($_POST['version'] ?? '1.0');\n $yamlContent = $_POST['yaml_content'] ?? '';\n $scopeDescription = trim($_POST['scope_description'] ?? '');\n $status = $_POST['status'] ?? 'active';\n\n if ($name === '' || $yamlContent === '') {\n if ($isHtmx) {\n $this->htmxError('Name und YAML-Inhalt sind erforderlich.');\n\n return;\n }\n $_SESSION['error'] = 'Name und YAML-Inhalt sind erforderlich.';\n $this->redirect('\/contracts\/new');\n }\n\n \/\/ YAML-Syntax validieren\n try {\n yaml_parse($yamlContent);\n } catch (\\Exception $e) {\n if ($isHtmx) {\n $this->htmxError('Ungültige YAML-Syntax: ' . $e->getMessage());\n\n return;\n }\n $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();\n $this->redirect('\/contracts\/new');\n }\n\n $contractId = $this->repository->create([\n 'name' => $name,\n 'version' => $version,\n 'yaml_content' => $yamlContent,\n 'scope_description' => $scopeDescription,\n 'status' => $status,\n ]);\n\n if ($isHtmx) {\n $this->htmxRedirect('\/contracts\/' . $contractId);\n\n return;\n }\n\n $_SESSION['success'] = 'Contract erfolgreich erstellt.';\n $this->redirect('\/contracts\/' . $contractId);\n }\n\n \/**\n * GET \/contracts\/{id}\n *\/\n public function show(string $id): void\n {\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $history = $this->repository->getHistory((int) $id);\n $validations = $this->repository->getValidations((int) $id, 10);\n\n $this->view('contracts.show', [\n 'title' => $contract['name'],\n 'contract' => $contract,\n 'history' => $history,\n 'validations' => $validations,\n ]);\n }\n\n \/**\n * GET \/contracts\/{id}\/edit\n *\/\n public function edit(string $id): void\n {\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $this->view('contracts.edit', [\n 'title' => 'Contract bearbeiten: ' . $contract['name'],\n 'contract' => $contract,\n ]);\n }\n\n \/**\n * POST \/contracts\/{id}\n *\/\n public function update(string $id): void\n {\n $this->requireCsrf();\n\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $yamlContent = $_POST['yaml_content'] ?? '';\n $newVersion = trim($_POST['new_version'] ?? '');\n $changeDescription = trim($_POST['change_description'] ?? '');\n\n if ($yamlContent === '' || $newVersion === '') {\n $_SESSION['error'] = 'YAML-Inhalt und neue Version sind erforderlich.';\n header('Location: \/contracts\/' . $id . '\/edit');\n exit;\n }\n\n \/\/ YAML-Syntax validieren\n try {\n yaml_parse($yamlContent);\n } catch (\\Exception $e) {\n $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();\n header('Location: \/contracts\/' . $id . '\/edit');\n exit;\n }\n\n $this->repository->createNewVersion(\n (int) $id,\n $yamlContent,\n $newVersion,\n $changeDescription\n );\n\n $_SESSION['success'] = 'Contract auf Version ' . $newVersion . ' aktualisiert.';\n header('Location: \/contracts\/' . $id);\n exit;\n }\n\n \/**\n * POST \/contracts\/{id}\/validate\n *\/\n public function validate(string $id): void\n {\n $this->requireCsrf();\n\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $result = $this->repository->runValidation((int) $id);\n\n if ($this->isHtmxRequest()) {\n $alertClass = $result['result'] === 'passed' ? 'success' : 'error';\n echo '<div class=\"alert alert--' . $alertClass . '\">';\n echo 'Validierung: <strong>' . htmlspecialchars($result['result']) . '<\/strong> ';\n echo '(Critical: ' . $result['critical'] . ', Major: ' . $result['major'] . ', Minor: ' . $result['minor'] . ')';\n echo '<\/div>';\n\n return;\n }\n\n $_SESSION['validation_result'] = $result;\n $this->redirect('\/contracts\/' . $id);\n }\n\n \/**\n * POST \/contracts\/{id}\/deprecate\n *\/\n public function deprecate(string $id): void\n {\n $this->requireCsrf();\n\n $contract = $this->repository->findById((int) $id);\n\n if ($contract === null) {\n $this->notFound('Contract nicht gefunden');\n }\n\n $this->repository->deprecate((int) $id);\n\n if ($this->isHtmxRequest()) {\n $this->htmxRedirect('\/contracts\/' . $id);\n\n return;\n }\n\n $_SESSION['success'] = 'Contract als deprecated markiert.';\n $this->redirect('\/contracts\/' . $id);\n }\n}\n",
"structuredPatch": [
{
"oldStart": 151,
"oldLines": 6,
"newStart": 151,
"newLines": 7,
"lines": [
" {",
" $this->requireCsrf();",
" ",
"+ $isHtmx = $this->isHtmxRequest();",
" $contract = $this->repository->findById((int) $id);",
" ",
" if ($contract === null) {"
]
},
{
"oldStart": 162,
"oldLines": 18,
"newStart": 163,
"newLines": 26,
"lines": [
" $changeDescription = trim($_POST['change_description'] ?? '');",
" ",
" if ($yamlContent === '' || $newVersion === '') {",
"+ if ($isHtmx) {",
"+ $this->htmxError('YAML-Inhalt und neue Version sind erforderlich.');",
"+",
"+ return;",
"+ }",
" $_SESSION['error'] = 'YAML-Inhalt und neue Version sind erforderlich.';",
"- header('Location: \/contracts\/' . $id . '\/edit');",
"- exit;",
"+ $this->redirect('\/contracts\/' . $id . '\/edit');",
" }",
" ",
" \/\/ YAML-Syntax validieren",
" try {",
" yaml_parse($yamlContent);",
" } catch (\\Exception $e) {",
"+ if ($isHtmx) {",
"+ $this->htmxError('Ungültige YAML-Syntax: ' . $e->getMessage());",
"+",
"+ return;",
"+ }",
" $_SESSION['error'] = 'Ungültige YAML-Syntax: ' . $e->getMessage();",
"- header('Location: \/contracts\/' . $id . '\/edit');",
"- exit;",
"+ $this->redirect('\/contracts\/' . $id . '\/edit');",
" }",
" ",
" $this->repository->createNewVersion("
]
},
{
"oldStart": 183,
"oldLines": 9,
"newStart": 192,
"newLines": 14,
"lines": [
" $changeDescription",
" );",
" ",
"+ if ($isHtmx) {",
"+ $this->htmxRedirect('\/contracts\/' . $id);",
"+",
"+ return;",
"+ }",
"+",
" $_SESSION['success'] = 'Contract auf Version ' . $newVersion . ' aktualisiert.';",
"- header('Location: \/contracts\/' . $id);",
"- exit;",
"+ $this->redirect('\/contracts\/' . $id);",
" }",
" ",
" \/**"
]
}
],
"userModified": false,
"replaceAll": false
}
}