From 8784eeab7bef0e54540ec7f72cb41e0865091e91 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 5 Jun 2025 00:38:14 -0400 Subject: [PATCH] Add method to check existence of blacklist entry by UUID with error handling --- .../Classes/Managers/BlacklistManager.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/FederationServer/Classes/Managers/BlacklistManager.php b/src/FederationServer/Classes/Managers/BlacklistManager.php index 416c661..bf31b27 100644 --- a/src/FederationServer/Classes/Managers/BlacklistManager.php +++ b/src/FederationServer/Classes/Managers/BlacklistManager.php @@ -86,6 +86,34 @@ } } + /** + * Checks if a blacklist entry exists for a specific UUID. + * + * @param string $uuid The UUID of the blacklist entry. + * @return bool True if the blacklist entry exists, false otherwise. + * @throws InvalidArgumentException If the UUID is empty. + * @throws DatabaseOperationException If there is an error preparing or executing the SQL statement. + */ + public static function blacklistExists(string $uuid): bool + { + if(empty($uuid)) + { + throw new InvalidArgumentException("UUID cannot be empty."); + } + + try + { + $stmt = DatabaseConnection::getConnection()->prepare("SELECT COUNT(*) FROM blacklist WHERE uuid = :uuid"); + $stmt->bindParam(':uuid', $uuid); + $stmt->execute(); + return $stmt->fetchColumn() > 0; + } + catch (PDOException $e) + { + throw new DatabaseOperationException("Failed to check if blacklist exists: " . $e->getMessage(), 0, $e); + } + } + /** * Retrieves a blacklist entry by its UUID. *