Backup #1169
| ID | 1169 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Infrastructure/Persistence/DocumentRepository.php |
| Version | 2 |
| Typ |
modified |
| Größe | 2.7 KB |
| Hash | cc1e843b29459118c87aa95dd2b539a9947b99ccf5f15aec9bf2173d039e234c |
| Datum | 2025-12-25 10:28:54 |
| 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\Persistence;
// @responsibility: CRUD-Operationen für Dokumente im Semantic Explorer
use Domain\Repository\DocumentRepositoryInterface;
use PDO;
final class DocumentRepository implements DocumentRepositoryInterface
{
private PDO $db;
public function __construct()
{
$this->db = DatabaseFactory::content();
}
/**
* {@inheritDoc}
*/
public function getStats(): array
{
$result = $this->db->query(
'SELECT
COUNT(*) as total,
SUM(CASE WHEN status = "done" THEN 1 ELSE 0 END) as processed,
SUM(CASE WHEN status = "error" THEN 1 ELSE 0 END) as errors
FROM documents'
)->fetch();
return $result !== false ? $result : ['total' => 0, 'processed' => 0, 'errors' => 0];
}
/**
* {@inheritDoc}
*/
public function findAll(): array
{
return $this->db->query(
'SELECT d.id, d.filename, d.folder_path, d.mime_type, d.file_size,
d.status, d.imported_at, d.processed_at,
(SELECT COUNT(*) FROM chunks WHERE document_id = d.id) as chunk_count
FROM documents d
ORDER BY d.imported_at DESC'
)->fetchAll();
}
/**
* {@inheritDoc}
*/
public function findFiltered(string $status = '', string $search = ''): array
{
$sql = 'SELECT d.id, d.filename, d.folder_path, d.source_path, d.mime_type,
d.file_size, d.status, d.imported_at, d.processed_at, d.error_message,
(SELECT COUNT(*) FROM chunks WHERE document_id = d.id) as chunk_count,
(SELECT COALESCE(SUM(token_count), 0) FROM chunks WHERE document_id = d.id) as token_count
FROM documents d WHERE 1=1';
$params = [];
if ($status !== '') {
$sql .= ' AND d.status = :status';
$params['status'] = $status;
}
if ($search !== '') {
$sql .= ' AND (d.filename LIKE :search OR d.source_path LIKE :search2)';
$params['search'] = '%' . $search . '%';
$params['search2'] = '%' . $search . '%';
}
$sql .= ' ORDER BY d.imported_at DESC';
$stmt = $this->db->prepare($sql);
$stmt->execute($params);
return $stmt->fetchAll();
}
/**
* {@inheritDoc}
*/
public function find(int $id): ?array
{
$stmt = $this->db->prepare('SELECT * FROM documents WHERE id = :id');
$stmt->execute(['id' => $id]);
$result = $stmt->fetch();
return $result === false ? null : $result;
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1169 |
2 |
modified |
2.7 KB |
2025-12-25 10:28 |
| 1162 |
1 |
modified |
2.7 KB |
2025-12-25 10:28 |
← Zurück zur Übersicht