diff --git a/src/FederationServer/Classes/Managers/AuditLogManager.php b/src/FederationServer/Classes/Managers/AuditLogManager.php index 925beab..013ddcd 100644 --- a/src/FederationServer/Classes/Managers/AuditLogManager.php +++ b/src/FederationServer/Classes/Managers/AuditLogManager.php @@ -75,6 +75,41 @@ } } + /** + * Retrieves a specific audit log entry by its UUID. + * + * @param string $uuid The UUID of the audit log entry to retrieve. + * @return AuditLogRecord|null An AuditLogRecord object representing the entry, or null if not found. + * @throws InvalidArgumentException If the UUID is empty. + * @throws DatabaseOperationException If there is an error preparing or executing the SQL statement. + */ + public static function getEntry(string $uuid): ?AuditLogRecord + { + if(strlen($uuid) === 0) + { + throw new InvalidArgumentException("UUID cannot be empty."); + } + + try + { + $stmt = DatabaseConnection::getConnection()->prepare("SELECT * FROM audit_log WHERE uuid = :uuid"); + $stmt->bindParam(':uuid', $uuid); + $stmt->execute(); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + if ($result === false) + { + return null; // No entry found + } + + return new AuditLogRecord($result); + } + catch (PDOException $e) + { + throw new DatabaseOperationException("Failed to retrieve audit log entry: " . $e->getMessage(), 0, $e); + } + } + /** * Retrieves audit log entries with optional pagination and filtering. * diff --git a/src/FederationServer/Methods/Audit/ViewAuditEntry.php b/src/FederationServer/Methods/Audit/ViewAuditEntry.php index 800d16b..67dfaa8 100644 --- a/src/FederationServer/Methods/Audit/ViewAuditEntry.php +++ b/src/FederationServer/Methods/Audit/ViewAuditEntry.php @@ -6,6 +6,7 @@ use FederationServer\Classes\Managers\EntitiesManager; use FederationServer\Classes\Managers\OperatorManager; use FederationServer\Classes\RequestHandler; + use FederationServer\Classes\Validate; use FederationServer\Exceptions\DatabaseOperationException; use FederationServer\Exceptions\RequestException; use FederationServer\FederationServer;