diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php index e7838f857dcadf7b88e1df200f85a63033d5c0cd..77492f89ee682d5dc159c89d7dfb0e470635ce92 100644 --- a/plugins/tasks/Archive.php +++ b/plugins/tasks/Archive.php @@ -1,5 +1,7 @@ <?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."; }