@@ -156,5 +156,14 @@ $this->pdo->exec("
|
||||
INSERT OR IGNORE INTO log_entries_fts(rowid, line, source_name)
|
||||
SELECT id, line, source_name FROM log_entries
|
||||
");
|
||||
|
||||
$this->pdo->exec("
|
||||
CREATE TABLE IF NOT EXISTS false_positives (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
pattern TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT DEFAULT (datetime('now'))
|
||||
)
|
||||
");
|
||||
}
|
||||
}
|
||||
@@ -290,4 +290,52 @@ class Repository
|
||||
|
||||
return $row['count'] <= 1;
|
||||
}
|
||||
|
||||
// --- False Positives ---
|
||||
|
||||
public function getFalsePositives(): array
|
||||
{
|
||||
return $this->db->pdo()->query(
|
||||
"SELECT id, pattern, description, created_at FROM false_positives ORDER BY id"
|
||||
)->fetchAll();
|
||||
}
|
||||
|
||||
public function createFalsePositive(string $pattern, string $description = ''): array
|
||||
{
|
||||
$stmt = $this->db->pdo()->prepare(
|
||||
"INSERT INTO false_positives (pattern, description) VALUES (?, ?)"
|
||||
);
|
||||
$stmt->execute([$pattern, $description]);
|
||||
$id = (int) $this->db->pdo()->lastInsertId();
|
||||
return $this->getFalsePositive($id);
|
||||
}
|
||||
|
||||
public function getFalsePositive(int $id): ?array
|
||||
{
|
||||
$stmt = $this->db->pdo()->prepare(
|
||||
"SELECT id, pattern, description, created_at FROM false_positives WHERE id = ?"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
public function deleteFalsePositive(int $id): void
|
||||
{
|
||||
$this->db->pdo()->prepare("DELETE FROM false_positives WHERE id = ?")->execute([$id]);
|
||||
}
|
||||
|
||||
public function isFalsePositive(string $line): bool
|
||||
{
|
||||
$patterns = $this->db->pdo()->query(
|
||||
"SELECT pattern FROM false_positives"
|
||||
)->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
foreach ($patterns as $pattern) {
|
||||
if (preg_match($pattern, $line)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user