Commit 40534d78 authored by Oana-Eliza Alexa's avatar Oana-Eliza Alexa
Browse files

change to audit

1 merge request!74Draft: Resolve "Redesign audit class"
Showing with 45 additions and 14 deletions
+45 -14
...@@ -4,10 +4,12 @@ class Audit implements EndpointInterface ...@@ -4,10 +4,12 @@ class Audit implements EndpointInterface
{ {
private TaskGateway $gateway; private TaskGateway $gateway;
private string $errorMessage;
public function __construct (TaskGateway $gateway) public function __construct (TaskGateway $gateway)
{ {
$this->gateway = $gateway; $this->gateway = $gateway;
$this->errorMessage = 'No audit requiring removal';
} }
/** /**
...@@ -47,13 +49,12 @@ class Audit implements EndpointInterface ...@@ -47,13 +49,12 @@ class Audit implements EndpointInterface
$result = $this->processAuditDeletion($this->gateway->getObjectTypeTask('Audit')); $result = $this->processAuditDeletion($this->gateway->getObjectTypeTask('Audit'));
// Recursive function to filter out empty arrays at any depth // Recursive function to filter out empty arrays at any depth
$nonEmptyResults = Utils::recursiveArrayFilter($result); $filteredResults = Utils::recursiveArrayFilter($result);
if (!empty($nonEmptyResults)) { if (empty($filteredResults)) {
return $nonEmptyResults; return [$this->errorMessage];
} else {
return ['No audit requiring removal'];
} }
return $filteredResults;
} }
/** /**
...@@ -66,23 +67,30 @@ class Audit implements EndpointInterface ...@@ -66,23 +67,30 @@ class Audit implements EndpointInterface
$result = []; $result = [];
foreach ($auditSubTasks as $task) { foreach ($auditSubTasks as $task) {
// If the tasks must be treated - status and scheduled - process the sub-tasks // If the tasks must be treated - status and scheduled - process the sub-tasks
if ($this->gateway->statusAndScheduleCheck($task)) { if ($this->gateway->statusAndScheduleCheck($task)) {
$result[] = $this->processScheduledTask($task);
// Retrieve data from the main task.
$auditMainTask = $this->getAuditMainTask($task['fdtasksgranularmaster'][0]);
// Simply get the days to retain audit.
$auditRetention = $auditMainTask[0]['fdaudittasksretention'][0];
// Verification of all audit and their potential removal based on retention days passed, also update subtasks.
$result[] = $this->checkAuditPassedRetention($auditRetention, $task['dn'], $task['cn'][0]);
} }
} }
return $result; return $result;
} }
/**
* @param array $task
* @return array
* @throws Exception
*/
private function processScheduledTask(array $task): array
{
// Retrieve data from the main task.
$auditMainTask = $this->getAuditMainTask($task['fdtasksgranularmaster'][0]);
// Simply get the days to retain audit.
$auditRetention = $auditMainTask[0]['fdaudittasksretention'][0];
// Verification of all audit and their potential removal based on retention days passed, also update subtasks.
return $this->checkAuditPassedRetention($auditRetention, $task['dn'], $task['cn'][0]);
}
/** /**
* @param string $mainTaskDn * @param string $mainTaskDn
* @return array * @return array
...@@ -119,4 +127,27 @@ class Audit implements EndpointInterface ...@@ -119,4 +127,27 @@ class Audit implements EndpointInterface
return $audit; return $audit;
} }
/**
* @param array $array
* @return array
* Note : Recursively filters out empty values and arrays at any depth.
*/
private function recursiveArrayFilter (array $array): array
{
// First filter the array for non-empty elements
$filtered = array_filter($array, function ($item) {
if (is_array($item)) {
// Recursively filter the sub-array
$item = $this->recursiveArrayFilter($item);
// Only retain non-empty arrays
return !empty($item);
} else {
// Retain non-empty scalar values
return !empty($item);
}
});
return $filtered;
}
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment