Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
fusiondirectory-orchestrator
Commits
40534d78
Commit
40534d78
authored
1 month ago
by
Oana-Eliza Alexa
Browse files
Options
Download
Patches
Plain Diff
change to audit
parent
fc915a52
78-redesign-audit-class
1 merge request
!74
Draft: Resolve "Redesign audit class"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/tasks/Audit.php
+45
-14
plugins/tasks/Audit.php
with
45 additions
and
14 deletions
+45
-14
plugins/tasks/Audit.php
+
45
−
14
View file @
40534d78
...
@@ -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
$
nonEmpty
Results
=
Utils
::
recursiveArrayFilter
(
$result
);
$
filtered
Results
=
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
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets