{
"event": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Config\/ManageConfigUseCase.php",
"old_string": " public function create(\n string $type,\n string $name,\n string $slug,\n ?string $description,\n string $content,\n string $version,\n string $status,\n ?int $parentId\n ): ConfigResult {\n $name = trim($name);\n $slug = trim($slug);\n $description = $description !== null ? trim($description) : null;\n\n if (!in_array($type, self::VALID_TYPES, true)) {\n return ConfigResult::error('Ungültiger Konfigurationstyp.');\n }\n\n if ($name === '' || $slug === '') {\n return ConfigResult::error('Name und Slug sind erforderlich.');\n }\n\n if (!$this->isValidJson($content)) {\n return ConfigResult::error('Ungültiges JSON-Format.');\n }\n\n $id = $this->configRepo->create(\n $type,\n $name,\n $slug,\n $description !== '' ? $description : null,\n $content,\n trim($version) ?: '1.0',\n in_array($status, self::VALID_STATUSES, true) ? $status : 'draft',\n $parentId\n );\n\n return ConfigResult::success($id, 'Konfiguration erfolgreich erstellt.');\n }",
"new_string": " public function create(\n string $type,\n string $name,\n string $slug,\n ?string $description,\n string $content,\n string $version,\n string $status,\n ?int $parentId,\n ?int $promptId = null,\n int $sortOrder = 0\n ): ConfigResult {\n $name = trim($name);\n $slug = trim($slug);\n $description = $description !== null ? trim($description) : null;\n\n if (!in_array($type, self::VALID_TYPES, true)) {\n return ConfigResult::error('Ungültiger Konfigurationstyp.');\n }\n\n if ($name === '' || $slug === '') {\n return ConfigResult::error('Name und Slug sind erforderlich.');\n }\n\n if (!$this->isValidJson($content)) {\n return ConfigResult::error('Ungültiges JSON-Format.');\n }\n\n $id = $this->configRepo->create(\n $type,\n $name,\n $slug,\n $description !== '' ? $description : null,\n $content,\n trim($version) ?: '1.0',\n in_array($status, self::VALID_STATUSES, true) ? $status : 'draft',\n $parentId,\n $promptId,\n $sortOrder\n );\n\n return ConfigResult::success($id, 'Konfiguration erfolgreich erstellt.');\n }"
}
}
{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Config\/ManageConfigUseCase.php",
"oldString": " public function create(\n string $type,\n string $name,\n string $slug,\n ?string $description,\n string $content,\n string $version,\n string $status,\n ?int $parentId\n ): ConfigResult {\n $name = trim($name);\n $slug = trim($slug);\n $description = $description !== null ? trim($description) : null;\n\n if (!in_array($type, self::VALID_TYPES, true)) {\n return ConfigResult::error('Ungültiger Konfigurationstyp.');\n }\n\n if ($name === '' || $slug === '') {\n return ConfigResult::error('Name und Slug sind erforderlich.');\n }\n\n if (!$this->isValidJson($content)) {\n return ConfigResult::error('Ungültiges JSON-Format.');\n }\n\n $id = $this->configRepo->create(\n $type,\n $name,\n $slug,\n $description !== '' ? $description : null,\n $content,\n trim($version) ?: '1.0',\n in_array($status, self::VALID_STATUSES, true) ? $status : 'draft',\n $parentId\n );\n\n return ConfigResult::success($id, 'Konfiguration erfolgreich erstellt.');\n }",
"newString": " public function create(\n string $type,\n string $name,\n string $slug,\n ?string $description,\n string $content,\n string $version,\n string $status,\n ?int $parentId,\n ?int $promptId = null,\n int $sortOrder = 0\n ): ConfigResult {\n $name = trim($name);\n $slug = trim($slug);\n $description = $description !== null ? trim($description) : null;\n\n if (!in_array($type, self::VALID_TYPES, true)) {\n return ConfigResult::error('Ungültiger Konfigurationstyp.');\n }\n\n if ($name === '' || $slug === '') {\n return ConfigResult::error('Name und Slug sind erforderlich.');\n }\n\n if (!$this->isValidJson($content)) {\n return ConfigResult::error('Ungültiges JSON-Format.');\n }\n\n $id = $this->configRepo->create(\n $type,\n $name,\n $slug,\n $description !== '' ? $description : null,\n $content,\n trim($version) ?: '1.0',\n in_array($status, self::VALID_STATUSES, true) ? $status : 'draft',\n $parentId,\n $promptId,\n $sortOrder\n );\n\n return ConfigResult::success($id, 'Konfiguration erfolgreich erstellt.');\n }",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Config;\n\n\/\/ @responsibility: Verwaltet Content-Konfigurationen (Profile, Strukturen, Contracts)\n\nuse Infrastructure\\Persistence\\ContentConfigRepository;\n\nfinal class ManageConfigUseCase\n{\n private const VALID_TYPES = ['author_profile', 'structure', 'organization', 'contract', 'rule', 'system_prompt', 'critic'];\n private const VALID_STATUSES = ['draft', 'active', 'deprecated'];\n\n public function __construct(\n private ContentConfigRepository $configRepo\n ) {\n }\n\n public function getAll(?string $type = null, ?string $status = null): array\n {\n $validType = in_array($type, self::VALID_TYPES, true) ? $type : null;\n $validStatus = in_array($status, self::VALID_STATUSES, true) ? $status : null;\n\n return array_map(\n fn (array $row) => ConfigDTO::fromArray($row),\n $this->configRepo->findAll($validType, $validStatus)\n );\n }\n\n public function getById(int $id): ?ConfigDTO\n {\n $data = $this->configRepo->findById($id);\n\n return $data !== null ? ConfigDTO::fromArray($data) : null;\n }\n\n public function create(\n string $type,\n string $name,\n string $slug,\n ?string $description,\n string $content,\n string $version,\n string $status,\n ?int $parentId\n ): ConfigResult {\n $name = trim($name);\n $slug = trim($slug);\n $description = $description !== null ? trim($description) : null;\n\n if (!in_array($type, self::VALID_TYPES, true)) {\n return ConfigResult::error('Ungültiger Konfigurationstyp.');\n }\n\n if ($name === '' || $slug === '') {\n return ConfigResult::error('Name und Slug sind erforderlich.');\n }\n\n if (!$this->isValidJson($content)) {\n return ConfigResult::error('Ungültiges JSON-Format.');\n }\n\n $id = $this->configRepo->create(\n $type,\n $name,\n $slug,\n $description !== '' ? $description : null,\n $content,\n trim($version) ?: '1.0',\n in_array($status, self::VALID_STATUSES, true) ? $status : 'draft',\n $parentId\n );\n\n return ConfigResult::success($id, 'Konfiguration erfolgreich erstellt.');\n }\n\n public function update(\n int $id,\n string $name,\n string $slug,\n ?string $description,\n string $content,\n string $newVersion,\n string $changeDescription,\n string $status,\n ?int $parentId\n ): ConfigResult {\n $name = trim($name);\n $slug = trim($slug);\n $newVersion = trim($newVersion);\n $description = $description !== null ? trim($description) : null;\n\n $existing = $this->configRepo->findById($id);\n if ($existing === null) {\n return ConfigResult::error('Konfiguration nicht gefunden.');\n }\n\n if ($name === '' || $slug === '' || $newVersion === '') {\n return ConfigResult::error('Name, Slug und neue Version sind erforderlich.');\n }\n\n if (!$this->isValidJson($content)) {\n return ConfigResult::error('Ungültiges JSON-Format.');\n }\n\n $this->configRepo->saveHistory(\n $id,\n $existing['content'],\n $existing['version'],\n 'web-ui',\n $changeDescription !== '' ? $changeDescription : 'Update auf Version ' . $newVersion\n );\n\n $this->configRepo->update(\n $id,\n $name,\n $slug,\n $description !== '' ? $description : null,\n $content,\n $newVersion,\n in_array($status, self::VALID_STATUSES, true) ? $status : $existing['status'],\n $parentId\n );\n\n return ConfigResult::success($id, 'Konfiguration auf Version ' . $newVersion . ' aktualisiert.');\n }\n\n public function delete(int $id): ConfigResult\n {\n $existing = $this->configRepo->findById($id);\n if ($existing === null) {\n return ConfigResult::error('Konfiguration nicht gefunden.');\n }\n\n if ($this->configRepo->countChildren($id) > 0) {\n return ConfigResult::error('Kann nicht gelöscht werden: Es existieren verknüpfte Einträge.');\n }\n\n $this->configRepo->deleteHistory($id);\n $this->configRepo->delete($id);\n\n return ConfigResult::success($id, 'Konfiguration gelöscht.');\n }\n\n public function getChildren(int $id): array\n {\n return $this->configRepo->getChildren($id);\n }\n\n public function getHistory(int $id): array\n {\n return $this->configRepo->getHistory($id);\n }\n\n public function getParentOptions(?int $excludeId = null): array\n {\n return $this->configRepo->getParentOptions($excludeId);\n }\n\n public function getStatistics(): array\n {\n return $this->configRepo->getStatistics();\n }\n\n private function isValidJson(string $content): bool\n {\n if ($content === 'null') {\n return true;\n }\n\n json_decode($content, true);\n\n return json_last_error() === JSON_ERROR_NONE;\n }\n}\n",
"structuredPatch": [
{
"oldStart": 44,
"oldLines": 7,
"newStart": 44,
"newLines": 9,
"lines": [
" string $content,",
" string $version,",
" string $status,",
"- ?int $parentId",
"+ ?int $parentId,",
"+ ?int $promptId = null,",
"+ int $sortOrder = 0",
" ): ConfigResult {",
" $name = trim($name);",
" $slug = trim($slug);"
]
},
{
"oldStart": 70,
"oldLines": 7,
"newStart": 72,
"newLines": 9,
"lines": [
" $content,",
" trim($version) ?: '1.0',",
" in_array($status, self::VALID_STATUSES, true) ? $status : 'draft',",
"- $parentId",
"+ $parentId,",
"+ $promptId,",
"+ $sortOrder",
" );",
" ",
" return ConfigResult::success($id, 'Konfiguration erfolgreich erstellt.');"
]
}
],
"userModified": false,
"replaceAll": false
}
}