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

:sparkles: feat(archive) - enhance Archive functionality with WebServiceCall...

:sparkles: feat(archive) - enhance Archive functionality with WebServiceCall integration and improved error handling
2 merge requests!80Resolve "[Orchestrator] - Create a librabry in core orchestrator",!78Draft: Resolve "Redesign lifecycle class"
Showing with 28 additions and 10 deletions
+28 -10
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?php
use FusionDirectory\Rest\WebServiceCall;
class Archive implements EndpointInterface
{
private TaskGateway $gateway;
......@@ -30,11 +32,6 @@ class Archive implements EndpointInterface
$result = [];
$archiveTasks = $this->gateway->getObjectTypeTask('archive');
// Initialize the webservice object
// TODO
$webservice = new FusionDirectory\Rest\WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/archive', 'POST');
$webservice->setCurlSettings();
foreach ($archiveTasks as $task) {
// Verify the task status and schedule
if ($this->gateway->statusAndScheduleCheck($task)) {
......@@ -42,19 +39,32 @@ class Archive implements EndpointInterface
$userStatus = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
// Check if the user meets the "toBeArchived" condition
// TODO
if ($userStatus === 'toBeArchived') {
// Trigger the archive method via the webservice
$archiveResult = $webservice->triggerArchive($task['fdtasksgranulardn'][0]);
// Construct the archive URL
$archiveUrl = $_ENV['FUSION_DIRECTORY_API_URL'] . '/archive/user/' . rawurlencode($task['fdtasksgranulardn'][0]);
// Initialize the WebServiceCall object
$webServiceCall = new WebServiceCall($archiveUrl, 'POST');
$webServiceCall->setCurlSettings();
// Update the task status based on the result
if ($archiveResult === TRUE) {
// Execute the request
$response = curl_exec($webServiceCall->ch);
// Handle any cURL errors
$webServiceCall->handleCurlError($webServiceCall->ch);
// Decode and process the response
$responseData = json_decode($response, true);
if ($responseData && isset($responseData['success']) && $responseData['success'] === true) {
$result[$task['dn']]['result'] = "User successfully archived.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2'); // Mark task as completed
} else {
$result[$task['dn']]['result'] = "Error archiving user.";
$this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '3'); // Mark task as failed
}
// Close the cURL resource
curl_close($webServiceCall->ch);
} else {
$result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
}
......
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