From 78eb0e8430f70fede09ea6f9ca47d43766f3d85c Mon Sep 17 00:00:00 2001 From: janis steiner Date: Sat, 16 May 2026 12:38:42 +0200 Subject: [PATCH] fixing db bugs --- src/Storage/Repository.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Storage/Repository.php b/src/Storage/Repository.php index 3128a6a..3ab7adc 100644 --- a/src/Storage/Repository.php +++ b/src/Storage/Repository.php @@ -136,11 +136,11 @@ class Repository } if ($since) { $where[] = 'created_at >= ?'; - $params[] = $since; + $params[] = str_replace('T', ' ', $since); } if ($until) { $where[] = 'created_at <= ?'; - $params[] = $until; + $params[] = str_replace('T', ' ', $until); } $sql = "SELECT * FROM alerts"; @@ -207,11 +207,11 @@ class Repository if ($since) { $where[] = 'e.created_at >= ?'; - $params[] = $since; + $params[] = str_replace('T', ' ', $since); } if ($until) { $where[] = 'e.created_at <= ?'; - $params[] = $until; + $params[] = str_replace('T', ' ', $until); } if ($query === '*') { @@ -382,22 +382,28 @@ class Repository public function getAuditLog(int $limit = 50): array { - return $this->db->pdo()->prepare( + $stmt = $this->db->pdo()->prepare( "SELECT * FROM audit_log ORDER BY created_at DESC LIMIT ?" - )->execute([$limit])->fetchAll(); + ); + $stmt->execute([$limit]); + return $stmt->fetchAll(); } // --- Retention --- public function purgeOldData(int $logDays = 30, int $alertDays = 90): array { - $deletedLogs = $this->db->pdo()->prepare( + $stmt = $this->db->pdo()->prepare( "DELETE FROM log_entries WHERE created_at < datetime('now', ?)" - )->execute(['-' . $logDays . ' days'])->rowCount(); + ); + $stmt->execute(['-' . $logDays . ' days']); + $deletedLogs = $stmt->rowCount(); - $deletedAlerts = $this->db->pdo()->prepare( + $stmt = $this->db->pdo()->prepare( "DELETE FROM alerts WHERE status = 'resolved' AND created_at < datetime('now', ?)" - )->execute(['-' . $alertDays . ' days'])->rowCount(); + ); + $stmt->execute(['-' . $alertDays . ' days']); + $deletedAlerts = $stmt->rowCount(); $this->db->pdo()->exec("DELETE FROM rate_limiter WHERE window_start < " . (time() - 86400));