Protokoll #24494

ID24494
Zeitstempel2025-12-27 23:22:23.640913
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,739 (Input: 133, Output: 1,606)
Dauer100 ms
Request-Zeit2025-12-27 23:22:23.640913
Response-Zeit2025-12-27 23:22:23.741348

Request

{
    "event": "PreToolUse",
    "tool_name": "Edit",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Taxonomy\/AssignEntityTaxonomyUseCase.php",
        "old_string": "namespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Manuelle und automatische Entity-Taxonomie-Zuweisung\n\nuse Domain\\Entity\\EntityTaxonomyMapping;",
        "new_string": "namespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Manuelle und automatische Entity-Taxonomie-Zuweisung\n\nuse Domain\\Constants;\nuse Domain\\Entity\\EntityTaxonomyMapping;"
    }
}

Response

{
    "tool_response": {
        "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Taxonomy\/AssignEntityTaxonomyUseCase.php",
        "oldString": "namespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Manuelle und automatische Entity-Taxonomie-Zuweisung\n\nuse Domain\\Entity\\EntityTaxonomyMapping;",
        "newString": "namespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Manuelle und automatische Entity-Taxonomie-Zuweisung\n\nuse Domain\\Constants;\nuse Domain\\Entity\\EntityTaxonomyMapping;",
        "originalFile": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Taxonomy;\n\n\/\/ @responsibility: Manuelle und automatische Entity-Taxonomie-Zuweisung\n\nuse Domain\\Entity\\EntityTaxonomyMapping;\nuse Domain\\Repository\\EntityRepositoryInterface;\nuse Domain\\Repository\\EntityTaxonomyRepositoryInterface;\nuse Domain\\Repository\\TaxonomyRepositoryInterface;\nuse Domain\\ValueObject\\Confidence;\nuse Infrastructure\\Audit\\AuditService;\n\nfinal class AssignEntityTaxonomyUseCase\n{\n    public function __construct(\n        private EntityTaxonomyRepositoryInterface $entityTaxonomyRepository,\n        private EntityRepositoryInterface $entityRepository,\n        private TaxonomyRepositoryInterface $taxonomyRepository,\n        private AuditService $auditService\n    ) {\n    }\n\n    \/**\n     * Assign a taxonomy term to an entity.\n     *\n     * @throws \\InvalidArgumentException if validation fails\n     *\/\n    public function execute(\n        int $entityId,\n        int $taxonomyTermId,\n        float $relevance\n    ): int {\n        $this->validateEntity($entityId);\n        $this->validateTaxonomyTerm($taxonomyTermId);\n        $this->validateRelevance($relevance);\n\n        \/\/ Check if mapping already exists\n        if ($this->entityTaxonomyRepository->exists($entityId, $taxonomyTermId)) {\n            throw new \\InvalidArgumentException(\n                \"Mapping already exists for entity {$entityId} and term {$taxonomyTermId}\"\n            );\n        }\n\n        $mapping = new EntityTaxonomyMapping();\n        $mapping->setEntityId($entityId);\n        $mapping->setTaxonomyTermId($taxonomyTermId);\n        $mapping->setRelevance(Confidence::fromFloat($relevance));\n        $mapping->setValidated(false);\n\n        $id = $this->entityTaxonomyRepository->save($mapping);\n\n        $this->auditService->logCreate(\n            table: 'entity_taxonomy_mapping',\n            id: $id,\n            data: [\n                'entity_id' => $entityId,\n                'taxonomy_term_id' => $taxonomyTermId,\n                'relevance' => $relevance,\n                'validated' => false,\n            ],\n            actor: 'system',\n            actorType: 'pipeline'\n        );\n\n        return $id;\n    }\n\n    \/**\n     * Validate an existing mapping (mark as human-verified).\n     *\n     * @throws \\InvalidArgumentException if mapping not found\n     *\/\n    public function validateMapping(int $mappingId): void\n    {\n        $mappings = $this->entityTaxonomyRepository->getUnvalidatedMappings(1000);\n        $found = null;\n\n        foreach ($mappings as $mapping) {\n            if ($mapping->getId() === $mappingId) {\n                $found = $mapping;\n                break;\n            }\n        }\n\n        if ($found === null) {\n            \/\/ Check if mapping exists at all\n            $result = $this->entityTaxonomyRepository->markAsValidated($mappingId);\n            if (!$result) {\n                throw new \\InvalidArgumentException(\"Mapping {$mappingId} not found\");\n            }\n        } else {\n            $this->entityTaxonomyRepository->markAsValidated($mappingId);\n        }\n\n        $this->auditService->logUpdate(\n            table: 'entity_taxonomy_mapping',\n            id: $mappingId,\n            oldData: ['validated' => false],\n            newData: ['validated' => true],\n            actor: 'user',\n            actorType: 'user'\n        );\n    }\n\n    \/**\n     * Batch assign taxonomy terms to entities.\n     *\n     * @param array<array{entity_id: int, taxonomy_term_id: int, relevance: float}> $assignments\n     * @return array{success: int, errors: array<string>}\n     *\/\n    public function batchAssign(array $assignments): array\n    {\n        $successCount = 0;\n        $errors = [];\n\n        foreach ($assignments as $index => $assignment) {\n            try {\n                $this->execute(\n                    entityId: $assignment['entity_id'],\n                    taxonomyTermId: $assignment['taxonomy_term_id'],\n                    relevance: $assignment['relevance']\n                );\n                $successCount++;\n            } catch (\\Exception $e) {\n                $errors[] = \"Assignment {$index}: \" . $e->getMessage();\n            }\n        }\n\n        return [\n            'success' => $successCount,\n            'errors' => $errors,\n        ];\n    }\n\n    \/**\n     * Get validation statistics.\n     *\n     * @return array{total: int, validated: int, pending: int}\n     *\/\n    public function getValidationStats(): array\n    {\n        return $this->entityTaxonomyRepository->getValidationStats();\n    }\n\n    private function validateEntity(int $entityId): void\n    {\n        $entity = $this->entityRepository->find($entityId);\n        if ($entity === null) {\n            throw new \\InvalidArgumentException(\"Entity {$entityId} not found\");\n        }\n    }\n\n    private function validateTaxonomyTerm(int $termId): void\n    {\n        $term = $this->taxonomyRepository->find($termId);\n        if ($term === null) {\n            throw new \\InvalidArgumentException(\"Taxonomy term {$termId} not found\");\n        }\n    }\n\n    private function validateRelevance(float $relevance): void\n    {\n        if ($relevance < 0.0 || $relevance > 1.0) {\n            throw new \\InvalidArgumentException(\n                \"Relevance must be between 0.0 and 1.0, got {$relevance}\"\n            );\n        }\n    }\n}\n",
        "structuredPatch": [
            {
                "oldStart": 6,
                "oldLines": 6,
                "newStart": 6,
                "newLines": 7,
                "lines": [
                    " ",
                    " \/\/ @responsibility: Manuelle und automatische Entity-Taxonomie-Zuweisung",
                    " ",
                    "+use Domain\\Constants;",
                    " use Domain\\Entity\\EntityTaxonomyMapping;",
                    " use Domain\\Repository\\EntityRepositoryInterface;",
                    " use Domain\\Repository\\EntityTaxonomyRepositoryInterface;"
                ]
            }
        ],
        "userModified": false,
        "replaceAll": false
    }
}
← Vorheriger Zur Liste Nächster →