Commit 1ca9fdf4 authored by dockx thibault's avatar dockx thibault Committed by Oana-Eliza Alexa
Browse files

:art: style(archive) - apply consistent spacing in method signatures and improve code readability

1 merge request!75Draft: Resolve "Redesign Mail"
Showing with 56 additions and 56 deletions
+56 -56
...@@ -6,7 +6,7 @@ class Archive implements EndpointInterface ...@@ -6,7 +6,7 @@ class Archive implements EndpointInterface
{ {
private TaskGateway $gateway; private TaskGateway $gateway;
public function __construct(TaskGateway $gateway) public function __construct (TaskGateway $gateway)
{ {
$this->gateway = $gateway; $this->gateway = $gateway;
} }
...@@ -15,7 +15,7 @@ class Archive implements EndpointInterface ...@@ -15,7 +15,7 @@ class Archive implements EndpointInterface
* @return array * @return array
* Part of the interface of orchestrator plugin to treat GET method * Part of the interface of orchestrator plugin to treat GET method
*/ */
public function processEndPointGet(): array public function processEndPointGet (): array
{ {
// Retrieve tasks of type 'archive' // Retrieve tasks of type 'archive'
return $this->gateway->getObjectTypeTask('archive'); return $this->gateway->getObjectTypeTask('archive');
...@@ -27,7 +27,7 @@ class Archive implements EndpointInterface ...@@ -27,7 +27,7 @@ class Archive implements EndpointInterface
* @throws Exception * @throws Exception
* Note: Part of the interface of orchestrator plugin to treat PATCH method * Note: Part of the interface of orchestrator plugin to treat PATCH method
*/ */
public function processEndPointPatch(array $data = NULL): array public function processEndPointPatch (array $data = NULL): array
{ {
$result = []; $result = [];
$archiveTasks = $this->gateway->getObjectTypeTask('archive'); $archiveTasks = $this->gateway->getObjectTypeTask('archive');
...@@ -37,38 +37,38 @@ class Archive implements EndpointInterface ...@@ -37,38 +37,38 @@ class Archive implements EndpointInterface
$webServiceCall->setCurlSettings(); // Perform login and set the token $webServiceCall->setCurlSettings(); // Perform login and set the token
foreach ($archiveTasks as $task) { foreach ($archiveTasks as $task) {
try { try {
if (!$this->gateway->statusAndScheduleCheck($task)) { if (!$this->gateway->statusAndScheduleCheck($task)) {
// Skip this task if it does not meet the status and schedule criteria // Skip this task if it does not meet the status and schedule criteria
continue; continue;
}
// Receive null or 'toBeArchived'
$supannState = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
if ($supannState !== 'toBeArchived') {
// The task does not meet the criteria for archiving and can therefore be suppressed
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
$this->gateway->removeSubTask($task['dn']);
continue;
}
// Set the archive endpoint and method using the same WebServiceCall object
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
$webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request
$response = $webServiceCall->execute();
// Check if the HTTP status code is 204
if ($webServiceCall->getHttpStatusCode() === 204) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2');
} else {
throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode());
}
} catch (Exception $e) {
$result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage());
} }
// Receive null or 'toBeArchived'
$supannState = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
if ($supannState !== 'toBeArchived') {
// The task does not meet the criteria for archiving and can therefore be suppressed
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
$this->gateway->removeSubTask($task['dn']);
continue;
}
// Set the archive endpoint and method using the same WebServiceCall object
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
$webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request
$response = $webServiceCall->execute();
// Check if the HTTP status code is 204
if ($webServiceCall->getHttpStatusCode() === 204) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2');
} else {
throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode());
}
} catch (Exception $e) {
$result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage());
}
} }
return $result; return $result;
...@@ -79,7 +79,7 @@ class Archive implements EndpointInterface ...@@ -79,7 +79,7 @@ class Archive implements EndpointInterface
* @return array * @return array
* Note: Part of the interface of orchestrator plugin to treat POST method * Note: Part of the interface of orchestrator plugin to treat POST method
*/ */
public function processEndPointPost(array $data = NULL): array public function processEndPointPost (array $data = NULL): array
{ {
return []; return [];
} }
...@@ -89,7 +89,7 @@ class Archive implements EndpointInterface ...@@ -89,7 +89,7 @@ class Archive implements EndpointInterface
* @return array * @return array
* Note: Part of the interface of orchestrator plugin to treat DELETE method * Note: Part of the interface of orchestrator plugin to treat DELETE method
*/ */
public function processEndPointDelete(array $data = NULL): array public function processEndPointDelete (array $data = NULL): array
{ {
return []; return [];
} }
...@@ -99,7 +99,7 @@ class Archive implements EndpointInterface ...@@ -99,7 +99,7 @@ class Archive implements EndpointInterface
* @param string $userDn * @param string $userDn
* @return string|null * @return string|null
*/ */
private function getUserSupannAccountStatus(string $userDn): ?string private function getUserSupannAccountStatus (string $userDn): ?string
{ {
$supannState = $this->gateway->getLdapTasks( $supannState = $this->gateway->getLdapTasks(
'(objectClass=supannPerson)', '(objectClass=supannPerson)',
...@@ -107,31 +107,31 @@ class Archive implements EndpointInterface ...@@ -107,31 +107,31 @@ class Archive implements EndpointInterface
'', '',
$userDn $userDn
); );
if ($this->hasToBeArchived($supannState)) { if ($this->hasToBeArchived($supannState)) {
return 'toBeArchived'; return 'toBeArchived';
} }
return null; return NULL;
} }
private function hasToBeArchived(array $supannState): bool private function hasToBeArchived (array $supannState): bool
{ {
if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) { if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) {
return false; return FALSE;
} }
foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) { foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) {
// Skip non-numeric keys (e.g., 'count') // Skip non-numeric keys (e.g., 'count')
if (!is_numeric($key)) { if (!is_numeric($key)) {
continue; continue;
} }
if (strpos($value, '{COMPTE}I:toBeArchived') !== false) { if (strpos($value, '{COMPTE}I:toBeArchived') !== FALSE) {
return true; return TRUE;
}
} }
}
return false; return FALSE;
} }
} }
\ 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