{
"tool_response": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Persistence\/ContentOrderRepository.php",
"oldString": " \/**\n * Get settings from the last created order as defaults for new orders.\n *\n * @return array<string, mixed>\n *\/\n public function getLastOrderSettings(): array",
"newString": " \/**\n * Get settings from the last created order as defaults for new orders.\n *\n * @return array{model: string, collections: array<string>, context_limit: int, author_profile_id: int|null, contract_id: int|null, structure_id: int|null, temperature: float, max_tokens: int, system_prompt_id: int|null, selected_critics: array<int>, quality_check: bool}\n *\/\n public function getLastOrderSettings(): array",
"originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\Persistence;\n\n\/\/ @responsibility: Persistenz für Content-Orders\n\nuse Domain\\Repository\\ContentOrderRepositoryInterface;\nuse Infrastructure\\Traits\\JsonDecodeTrait;\n\nclass ContentOrderRepository implements ContentOrderRepositoryInterface\n{\n use JsonDecodeTrait;\n\n private \\PDO $pdo;\n\n public function __construct(\\PDO $pdo)\n {\n $this->pdo = $pdo;\n }\n\n public function findAllOrders(array $filters = [], int $limit = 50, int $offset = 0): array\n {\n $sql = 'SELECT co.*,\n ap.name as profile_name,\n cc.name as contract_name,\n cs.name as structure_name,\n sp.name as system_prompt_name,\n (SELECT COUNT(*) FROM content_versions WHERE order_id = co.id) as version_count\n FROM content_orders co\n LEFT JOIN content_config ap ON co.author_profile_id = ap.id AND ap.type = \"author_profile\"\n LEFT JOIN content_config cc ON co.contract_id = cc.id AND cc.type = \"contract\"\n LEFT JOIN content_config cs ON co.structure_id = cs.id AND cs.type = \"structure\"\n LEFT JOIN content_config sp ON co.system_prompt_id = sp.id AND sp.type = \"system_prompt\"\n WHERE 1=1';\n\n $params = [];\n\n if (isset($filters['status']) && $filters['status'] !== '') {\n $sql .= ' AND co.status = :status';\n $params['status'] = $filters['status'];\n }\n\n if (isset($filters['profile_id']) && $filters['profile_id'] !== '') {\n $sql .= ' AND co.author_profile_id = :profile_id';\n $params['profile_id'] = $filters['profile_id'];\n }\n\n $sql .= ' ORDER BY co.updated_at DESC LIMIT :limit OFFSET :offset';\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->bindValue(':offset', $offset, \\PDO::PARAM_INT);\n $stmt->execute();\n\n return $stmt->fetchAll();\n }\n\n public function findOrder(int $id): ?array\n {\n $stmt = $this->pdo->prepare('\n SELECT co.*,\n ap.name as profile_name, ap.content as profile_config,\n cc.name as contract_name, cc.content as contract_config,\n cs.name as structure_name, cs.content as structure_config,\n sp.name as system_prompt_name, sp.content as system_prompt_config\n FROM content_orders co\n LEFT JOIN content_config ap ON co.author_profile_id = ap.id AND ap.type = \"author_profile\"\n LEFT JOIN content_config cc ON co.contract_id = cc.id AND cc.type = \"contract\"\n LEFT JOIN content_config cs ON co.structure_id = cs.id AND cs.type = \"structure\"\n LEFT JOIN content_config sp ON co.system_prompt_id = sp.id AND sp.type = \"system_prompt\"\n WHERE co.id = :id\n ');\n $stmt->execute(['id' => $id]);\n $result = $stmt->fetch();\n\n return $result !== false ? $result : null;\n }\n\n \/**\n * Get settings from the last created order as defaults for new orders.\n *\n * @return array<string, mixed>\n *\/\n public function getLastOrderSettings(): array\n {\n $stmt = $this->pdo->query('\n SELECT model, collections, context_limit, author_profile_id, contract_id, structure_id,\n temperature, max_tokens, system_prompt_id, selected_critics, quality_check\n FROM content_orders\n ORDER BY id DESC\n LIMIT 1\n ');\n $row = $stmt->fetch(\\PDO::FETCH_ASSOC);\n\n if (!$row) {\n return [\n 'model' => 'claude-sonnet-4-20250514',\n 'collections' => ['documents'],\n 'context_limit' => 5,\n 'author_profile_id' => null,\n 'contract_id' => null,\n 'structure_id' => null,\n 'temperature' => 0.5,\n 'max_tokens' => 4096,\n 'system_prompt_id' => null,\n 'selected_critics' => [],\n 'quality_check' => false,\n ];\n }\n\n return [\n 'model' => $row['model'] ?? 'claude-sonnet-4-20250514',\n 'collections' => $this->decodeJsonArray($row['collections'] ?? null) ?: ['documents'],\n 'context_limit' => (int) ($row['context_limit'] ?? 5),\n 'author_profile_id' => $row['author_profile_id'] !== null ? (int) $row['author_profile_id'] : null,\n 'contract_id' => $row['contract_id'] !== null ? (int) $row['contract_id'] : null,\n 'structure_id' => $row['structure_id'] !== null ? (int) $row['structure_id'] : null,\n 'temperature' => (float) ($row['temperature'] ?? 0.5),\n 'max_tokens' => (int) ($row['max_tokens'] ?? 4096),\n 'system_prompt_id' => $row['system_prompt_id'] !== null ? (int) $row['system_prompt_id'] : null,\n 'selected_critics' => $this->decodeJsonArray($row['selected_critics'] ?? null) ?: [],\n 'quality_check' => (bool) ($row['quality_check'] ?? false),\n ];\n }\n\n public function createOrder(array $data): int\n {\n $stmt = $this->pdo->prepare(\"\n INSERT INTO content_orders\n (title, briefing, author_profile_id, contract_id, structure_id, model, collections, context_limit,\n temperature, max_tokens, system_prompt_id, selected_critics, quality_check, status)\n VALUES (:title, :briefing, :profile_id, :contract_id, :structure_id, :model, :collections, :context_limit,\n :temperature, :max_tokens, :system_prompt_id, :selected_critics, :quality_check, 'draft')\n \");\n\n $selectedCritics = $data['selected_critics'] ?? [];\n if (is_array($selectedCritics)) {\n $selectedCritics = json_encode(array_values(array_filter($selectedCritics)));\n }\n\n $stmt->execute([\n 'title' => $data['title'],\n 'briefing' => $data['briefing'],\n 'profile_id' => ($data['author_profile_id'] !== '' && $data['author_profile_id'] !== null) ? $data['author_profile_id'] : null,\n 'contract_id' => ($data['contract_id'] !== '' && $data['contract_id'] !== null) ? $data['contract_id'] : null,\n 'structure_id' => ($data['structure_id'] !== '' && $data['structure_id'] !== null) ? $data['structure_id'] : null,\n 'model' => $data['model'] ?? 'claude-sonnet-4-20250514',\n 'collections' => $data['collections'] ?? '[\"documents\"]',\n 'context_limit' => $data['context_limit'] ?? 5,\n 'temperature' => $data['temperature'] ?? 0.5,\n 'max_tokens' => $data['max_tokens'] ?? 4096,\n 'system_prompt_id' => ($data['system_prompt_id'] !== '' && $data['system_prompt_id'] !== null) ? $data['system_prompt_id'] : null,\n 'selected_critics' => $selectedCritics ?: null,\n 'quality_check' => !empty($data['quality_check']) ? 1 : 0,\n ]);\n\n return (int) $this->pdo->lastInsertId();\n }\n\n public function updateOrderStatus(int $id, string $status): void\n {\n $stmt = $this->pdo->prepare('\n UPDATE content_orders SET status = :status, updated_at = NOW() WHERE id = :id\n ');\n $stmt->execute(['id' => $id, 'status' => $status]);\n }\n\n public function updateGenerationStatus(int $id, string $status, ?string $error = null): void\n {\n $sql = 'UPDATE content_orders SET generation_status = :status, updated_at = NOW()';\n $params = ['id' => $id, 'status' => $status];\n\n if ($status === 'generating') {\n $sql .= ', generation_started_at = NOW()';\n }\n if ($error !== null) {\n $sql .= ', generation_error = :error';\n $params['error'] = $error;\n }\n if ($status === 'completed' || $status === 'idle') {\n $sql .= ', generation_error = NULL';\n }\n\n $sql .= ' WHERE id = :id';\n $stmt = $this->pdo->prepare($sql);\n $stmt->execute($params);\n }\n\n public function updateCritiqueStatus(int $id, string $status, ?string $error = null): void\n {\n $sql = 'UPDATE content_orders SET critique_status = :status, updated_at = NOW()';\n $params = ['id' => $id, 'status' => $status];\n\n if ($status === 'critiquing') {\n $sql .= ', critique_started_at = NOW(), critique_log = NULL';\n }\n if ($error !== null) {\n $sql .= ', critique_error = :error';\n $params['error'] = $error;\n }\n if ($status === 'completed' || $status === 'idle') {\n $sql .= ', critique_error = NULL';\n }\n\n $sql .= ' WHERE id = :id';\n $stmt = $this->pdo->prepare($sql);\n $stmt->execute($params);\n }\n\n public function updateOrder(int $id, array $data): bool\n {\n $stmt = $this->pdo->prepare('\n UPDATE content_orders SET\n title = :title,\n briefing = :briefing,\n author_profile_id = :profile_id,\n contract_id = :contract_id,\n structure_id = :structure_id,\n model = :model,\n collections = :collections,\n context_limit = :context_limit,\n temperature = :temperature,\n max_tokens = :max_tokens,\n system_prompt_id = :system_prompt_id,\n selected_critics = :selected_critics,\n quality_check = :quality_check,\n updated_at = NOW()\n WHERE id = :id\n ');\n\n $selectedCritics = $data['selected_critics'] ?? [];\n if (is_array($selectedCritics)) {\n $selectedCritics = json_encode(array_values(array_filter($selectedCritics)));\n }\n\n return $stmt->execute([\n ... [TRUNCATED-f8525561241327e7]",
"structuredPatch": [
{
"oldStart": 84,
"oldLines": 7,
"newStart": 84,
"newLines": 7,
"lines": [
" \/**",
" * Get settings from the last created order as defaults for new orders.",
" *",
"- * @return array<string, mixed>",
"+ * @return array{model: string, collections: array<string>, context_limit: int, author_profile_id: int|null, contract_id: int|null, structure_id: int|null, temperature: float, max_tokens: int, system_prompt_id: int|null, selected_critics: array<int>, quality_check: bool}",
" *\/",
" public function getLastOrderSettings(): array",
" {"
]
}
],
"userModified": false,
"replaceAll": false
}
}