Add method to check existence of blacklist entry by UUID with error handling

This commit is contained in:
netkas 2025-06-05 00:38:14 -04:00
parent 17fcc4321f
commit 8784eeab7b
Signed by: netkas
GPG key ID: 4D8629441B76E4CC

View file

@ -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. * Retrieves a blacklist entry by its UUID.
* *