Refactor audit log retrieval to use toPublicAuditRecord method for improved readability and maintainability
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
This commit is contained in:
parent
1a8f3626bc
commit
1739c8dd59
4 changed files with 35 additions and 55 deletions
|
@ -8,6 +8,7 @@
|
|||
use FederationServer\Classes\Logger;
|
||||
use FederationServer\Exceptions\DatabaseOperationException;
|
||||
use FederationServer\Objects\AuditLogRecord;
|
||||
use FederationServer\Objects\PublicAuditRecord;
|
||||
use InvalidArgumentException;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
@ -313,6 +314,31 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an AuditLogRecord to a PublicAuditRecord.
|
||||
*
|
||||
* @param AuditLogRecord $record The AuditLogRecord to convert.
|
||||
* @return PublicAuditRecord The converted PublicAuditRecord.
|
||||
* @throws DatabaseOperationException Thrown if there was a database error while transforming the record.
|
||||
*/
|
||||
public static function toPublicAuditRecord(AuditLogRecord $record): PublicAuditRecord
|
||||
{
|
||||
$operatorRecord = null;
|
||||
$entityRecord = null;
|
||||
|
||||
if($record->getOperator() !== null)
|
||||
{
|
||||
$operatorRecord = OperatorManager::getOperator($record->getOperator());
|
||||
}
|
||||
|
||||
if($record->getEntity() !== null)
|
||||
{
|
||||
$entityRecord = EntitiesManager::getEntityByUuid($record->getEntity());
|
||||
}
|
||||
|
||||
return new PublicAuditRecord($record, $operatorRecord, $entityRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all audit log entries.
|
||||
*
|
||||
|
|
|
@ -51,27 +51,11 @@
|
|||
$filteredEntries = null;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$auditLogs = AuditLogManager::getEntries($limit, $page, $filteredEntries);
|
||||
foreach($auditLogs as $logRecord)
|
||||
{
|
||||
$operatorRecord = null;
|
||||
$entityRecord = null;
|
||||
|
||||
if($logRecord->getOperator() !== null)
|
||||
{
|
||||
$operatorRecord = OperatorManager::getOperator($logRecord->getOperator());
|
||||
}
|
||||
|
||||
if($logRecord->getEntity() !== null)
|
||||
{
|
||||
$entityRecord = EntitiesManager::getEntityByUuid($logRecord->getEntity());
|
||||
}
|
||||
|
||||
$results[] = new PublicAuditRecord($logRecord, $operatorRecord, $entityRecord);
|
||||
}
|
||||
$results = array_map(fn($log) => AuditLogManager::toPublicAuditRecord($log),
|
||||
AuditLogManager::getEntries($limit, $page, $filteredEntries)
|
||||
);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
|
|
|
@ -69,24 +69,9 @@
|
|||
throw new RequestException('Not Found: Entity with the specified UUID does not exist', 404);
|
||||
}
|
||||
|
||||
$auditLogs = AuditLogManager::getEntriesByEntity($entityUuid, $limit, $page, $filteredEntries);
|
||||
foreach($auditLogs as $logRecord)
|
||||
{
|
||||
$operatorRecord = null;
|
||||
$entityRecord = null;
|
||||
|
||||
if($logRecord->getOperator() !== null)
|
||||
{
|
||||
$operatorRecord = OperatorManager::getOperator($logRecord->getOperator());
|
||||
}
|
||||
|
||||
if($logRecord->getEntity() !== null)
|
||||
{
|
||||
$entityRecord = EntitiesManager::getEntityByUuid($logRecord->getEntity());
|
||||
}
|
||||
|
||||
$results[] = new PublicAuditRecord($logRecord, $operatorRecord, $entityRecord);
|
||||
}
|
||||
$results = array_map(fn($log) => AuditLogManager::toPublicAuditRecord($log),
|
||||
AuditLogManager::getEntriesByEntity($entityUuid, $limit, $page, $filteredEntries)
|
||||
);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
|
|
|
@ -69,24 +69,9 @@
|
|||
throw new RequestException('Not Found: Operator with the specified UUID does not exist', 404);
|
||||
}
|
||||
|
||||
$auditLogs = AuditLogManager::getEntriesByOperator($operatorUuid, $limit, $page, $filteredEntries);
|
||||
foreach($auditLogs as $logRecord)
|
||||
{
|
||||
$operatorRecord = null;
|
||||
$entityRecord = null;
|
||||
|
||||
if($logRecord->getOperator() !== null)
|
||||
{
|
||||
$operatorRecord = OperatorManager::getOperator($logRecord->getOperator());
|
||||
}
|
||||
|
||||
if($logRecord->getEntity() !== null)
|
||||
{
|
||||
$entityRecord = EntitiesManager::getEntityByUuid($logRecord->getEntity());
|
||||
}
|
||||
|
||||
$results[] = new PublicAuditRecord($logRecord, $operatorRecord, $entityRecord);
|
||||
}
|
||||
$results = array_map(fn($log) => AuditLogManager::toPublicAuditRecord($log),
|
||||
AuditLogManager::getEntriesByOperator($operatorUuid, $limit, $page, $filteredEntries)
|
||||
);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue