+16
-10
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user