Backup #1439
| ID | 1439 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Infrastructure/Docs/ChunkDataRepository.php |
| Version | 1 |
| Typ |
modified |
| Größe | 4.6 KB |
| Hash | 00e7b79a2a42c26dc442a005dcdb744216273c427a9d7fb11a322d356e989ae2 |
| Datum | 2025-12-25 17:00:08 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Infrastructure\Docs;
// @responsibility: Datenbank-Operationen für dokumentation_chunks
use PDO;
final class ChunkRepository
{
public function __construct(
private PDO $pdo
) {
}
/**
* Gets a chunk by ID.
*
* @return array<string, mixed>|null
*/
public function findById(int $id): ?array
{
$stmt = $this->pdo->prepare('SELECT * FROM dokumentation_chunks WHERE id = :id');
$stmt->execute(['id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result !== false ? $result : null;
}
/**
* Gets pending chunks for analysis.
*
* @return array<array<string, mixed>>
*/
public function findPending(int $limit): array
{
$stmt = $this->pdo->prepare("
SELECT * FROM dokumentation_chunks
WHERE analysis_status = 'pending'
ORDER BY dokumentation_id, chunk_index
LIMIT :limit
");
$stmt->bindValue('limit', $limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
/**
* Gets document context by ID.
*
* @return array{title: string, path: string}
*/
public function getDocumentContext(int $docId): array
{
$stmt = $this->pdo->prepare('SELECT title, path FROM dokumentation WHERE id = :id');
$stmt->execute(['id' => $docId]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return [
'title' => $result['title'] ?? 'Unbekannt',
'path' => $result['path'] ?? '/',
];
}
/**
* Updates chunk analysis status.
*/
public function updateStatus(int $chunkId, string $status, ?string $error = null): void
{
$sql = 'UPDATE dokumentation_chunks
SET analysis_status = :status, analysis_error = :error
WHERE id = :id';
$stmt = $this->pdo->prepare($sql);
$stmt->execute(['id' => $chunkId, 'status' => $status, 'error' => $error]);
}
/**
* Stores analysis results.
*
* @param array{taxonomy: array<string>, entities: array<array{name: string, type: string}>, keywords: array<string>} $analysis
*/
public function storeAnalysisResults(int $chunkId, array $analysis, string $model): void
{
$taxonomyPath = $analysis['taxonomy'];
$taxonomyCategory = !empty($taxonomyPath) ? $taxonomyPath[0] : null;
$sql = "UPDATE dokumentation_chunks SET
taxonomy_category = :category,
taxonomy_path = :taxonomy,
entities = :entities,
keywords = :keywords,
analysis_model = :model,
analysis_status = 'completed',
analysis_error = NULL,
analyzed_at = NOW()
WHERE id = :id";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([
'id' => $chunkId,
'category' => $taxonomyCategory,
'taxonomy' => json_encode($taxonomyPath),
'entities' => json_encode($analysis['entities']),
'keywords' => json_encode($analysis['keywords']),
'model' => $model,
]);
}
/**
* Gets analysis statistics.
*
* @return array{pending: int, processing: int, completed: int, failed: int, by_category: array<array{category: string, count: int}>}
*/
public function getStats(): array
{
$stmt = $this->pdo->query("
SELECT
SUM(CASE WHEN analysis_status = 'pending' THEN 1 ELSE 0 END) as pending,
SUM(CASE WHEN analysis_status = 'processing' THEN 1 ELSE 0 END) as processing,
SUM(CASE WHEN analysis_status = 'completed' THEN 1 ELSE 0 END) as completed,
SUM(CASE WHEN analysis_status = 'failed' THEN 1 ELSE 0 END) as failed
FROM dokumentation_chunks
");
$counts = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $this->pdo->query('
SELECT taxonomy_category as category, COUNT(*) as count
FROM dokumentation_chunks
WHERE taxonomy_category IS NOT NULL
GROUP BY taxonomy_category
ORDER BY count DESC
');
$byCategory = $stmt->fetchAll(PDO::FETCH_ASSOC);
return [
'pending' => (int) ($counts['pending'] ?? 0),
'processing' => (int) ($counts['processing'] ?? 0),
'completed' => (int) ($counts['completed'] ?? 0),
'failed' => (int) ($counts['failed'] ?? 0),
'by_category' => $byCategory,
];
}
}
Vollständig herunterladen
Aktionen
← Zurück zur Übersicht