From 3a853974b9e2683f1d1f4f82989885977ca1bd2c Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:27:23 +0100
Subject: [PATCH 01/23] fix return

---
 plugins/tasks/Mail.php | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index 55ef06e..956e392 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -172,11 +172,7 @@ class Mail implements EndpointInterface
     // Multiplication is required to have the seconds
     $spamInterval = $spamInterval * 60;
     $antispam     = $lastExec + $spamInterval;
-    if ($antispam <= time()) {
-      return TRUE;
-    }
-
-    return FALSE;
+    return $antispam <= time();
   }
 
   /**
-- 
GitLab


From cfecbfdf455b99f8928478275c5f33edc47e8d28 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:52:56 +0100
Subject: [PATCH 02/23] refactor

---
 plugins/tasks/Mail.php | 82 +++++++++++++++++++++++-------------------
 1 file changed, 45 insertions(+), 37 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index 956e392..e0bac7d 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -64,14 +64,12 @@ class Mail implements EndpointInterface
 
     if ($this->verifySpamProtection($fdTasksConf)) {
       // Note : if list_tasks is empty, the controller receive null as result and will log/process it properly.
-      foreach ($tasks as $mail) {
-
-
+      foreach ($tasks as $task) {
         // verify status before processing (to be checked with schedule as well).
-        if ($mail["fdtasksgranularstatus"][0] == 1 && $this->gateway->verifySchedule($mail["fdtasksgranularschedule"][0])) {
+        if ($this->gateway->statusAndScheduleCheck($task)) {
 
           // Search for the related attached mail object.
-          $mailInfos   = $this->retrieveMailTemplateInfos($mail["fdtasksgranularref"][0]);
+          $mailInfos   = $this->retrieveMailTemplateInfos($task["fdtasksgranularref"][0]);
           $mailContent = $mailInfos[0];
 
           // Only takes arrays related to files attachments for the mail template selected
@@ -80,9 +78,9 @@ class Mail implements EndpointInterface
           $this->gateway->unsetCountKeys($mailInfos);
           $mailAttachments = array_values($mailInfos);
 
-          $setFrom    = $mail["fdtasksgranularmailfrom"][0];
-          $setBCC     = $mail["fdtasksgranularmailbcc"][0] ?? NULL;
-          $recipients = $mail["fdtasksgranularmail"];
+          $setFrom    = $task["fdtasksgranularmailfrom"][0];
+          $setBCC     = $task["fdtasksgranularmailbcc"][0] ?? NULL;
+          $recipients = $task["fdtasksgranularmail"];
           $body       = $mailContent["fdmailtemplatebody"][0];
           $signature  = $mailContent["fdmailtemplatesignature"][0] ?? NULL;
           $subject    = $mailContent["fdmailtemplatesubject"][0];
@@ -94,40 +92,14 @@ class Mail implements EndpointInterface
             $attachments[]       = $fileInfo;
           }
 
-          // Required before passing the array to the constructor mail.
-          if (empty($attachments)) {
-            $attachments = NULL;
-          }
-
-          $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
-                                                $setBCC,
-                                                $recipients,
-                                                $body,
-                                                $signature,
-                                                $subject,
-                                                $receipt,
-                                                $attachments);
-
-          $mailSentResult = $mail_controller->sendMail();
-
-          if ($mailSentResult[0] == "SUCCESS") {
-
-            // The third arguments "2" is the status code of success for mail as of now 18/11/22
-            $result[$mail["dn"]]['statusUpdate']       = $this->gateway->updateTaskStatus($mail["dn"], $mail["cn"][0], "2");
-            $result[$mail["dn"]]['mailStatus']         = 'mail : ' . $mail["dn"] . ' was successfully sent';
-            $result[$mail["dn"]]['updateLastMailExec'] = $this->gateway->updateLastMailExecTime($fdTasksConf[0]["dn"]);
-
-          } else {
-            $result[$mail["dn"]]['statusUpdate'] = $this->gateway->updateTaskStatus($mail["dn"], $mail["cn"][0], $mailSentResult[0]);
-            $result[$mail["dn"]]['Error']        = $mailSentResult;
-          }
+          $mailSentResult = $this->sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments);
+          $result[$task["dn"]] = $this->updateResult($mailSentResult, $task, $fdTasksConf);
 
           // Verification anti-spam max mails to be sent and quit loop if matched
           $maxMailsIncrement += 1; //Only one as recipients in mail object is always one email.
           if ($maxMailsIncrement == $maxMailsConfig) {
             break;
           }
-
         }
       }
     }
@@ -135,6 +107,43 @@ class Mail implements EndpointInterface
     return $result;
   }
 
+  private function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
+  {
+      // Required before passing the array to the constructor mail.
+      if (empty($attachments)) {
+          $attachments = NULL;
+      }
+
+      $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
+          $setBCC,
+          $recipients,
+          $body,
+          $signature,
+          $subject,
+          $receipt,
+          $attachments);
+
+      return $mail_controller->sendMail();
+  }
+
+  private function updateResult(array $mailSentResult, $task, $fdTasksConf): array
+  {
+      $result = [];
+      if ($mailSentResult[0] == "SUCCESS") {
+
+          // The third arguments "2" is the status code of success for mail as of now 18/11/22
+          $result['statusUpdate']       = $this->gateway->updateTaskStatus($task["dn"], $task["cn"][0], "2");
+          $result['mailStatus']         = 'mail : ' . $task["dn"] . ' was successfully sent';
+          $result['updateLastMailExec'] = $this->gateway->updateLastMailExecTime($fdTasksConf[0]["dn"]);
+
+      } else {
+          $result['statusUpdate'] = $this->gateway->updateTaskStatus($task["dn"], $task["cn"][0], $mailSentResult[0]);
+          $result['Error']        = $mailSentResult;
+      }
+
+      return $result;
+  }
+
   /**
    * @return array
    * Note : A simple retrieval methods of the mail backend configuration set in FusionDirectory
@@ -184,5 +193,4 @@ class Mail implements EndpointInterface
   {
     return $this->gateway->getLdapTasks("(|(objectClass=fdMailTemplate)(objectClass=fdMailAttachments))", [], $templateName);
   }
-
 }
-- 
GitLab


From 761c1b2bbd33444ae21b972684f7acceb639b667 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:58:43 +0100
Subject: [PATCH 03/23] fix indent

---
 plugins/tasks/Mail.php | 48 +++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index e0bac7d..c2b4cf5 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -110,38 +110,38 @@ class Mail implements EndpointInterface
   private function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
   {
       // Required before passing the array to the constructor mail.
-      if (empty($attachments)) {
-          $attachments = NULL;
-      }
+    if (empty($attachments))
+    {
+      $attachments = NULL;
+    }
 
-      $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
-          $setBCC,
-          $recipients,
-          $body,
-          $signature,
-          $subject,
-          $receipt,
-          $attachments);
+    $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
+      $setBCC,
+      $recipients,
+      $body,
+      $signature,
+      $subject,
+      $receipt,
+      $attachments);
 
       return $mail_controller->sendMail();
   }
 
   private function updateResult(array $mailSentResult, $task, $fdTasksConf): array
   {
-      $result = [];
-      if ($mailSentResult[0] == "SUCCESS") {
-
-          // The third arguments "2" is the status code of success for mail as of now 18/11/22
-          $result['statusUpdate']       = $this->gateway->updateTaskStatus($task["dn"], $task["cn"][0], "2");
-          $result['mailStatus']         = 'mail : ' . $task["dn"] . ' was successfully sent';
-          $result['updateLastMailExec'] = $this->gateway->updateLastMailExecTime($fdTasksConf[0]["dn"]);
-
-      } else {
-          $result['statusUpdate'] = $this->gateway->updateTaskStatus($task["dn"], $task["cn"][0], $mailSentResult[0]);
-          $result['Error']        = $mailSentResult;
-      }
+    $result = [];
+    if ($mailSentResult[0] == "SUCCESS") {
+      // The third arguments "2" is the status code of success for mail as of now 18/11/22
+      $result['statusUpdate']     = $this->gateway->updateTaskStatus($task["dn"], $task["cn"][0], "2");
+      $result['mailStatus']     = 'mail : ' . $task["dn"] . ' was successfully sent';
+      $result['updateLastMailExec'] = $this->gateway->updateLastMailExecTime($fdTasksConf[0]["dn"]);
+
+    } else {
+      $result['statusUpdate'] = $this->gateway->updateTaskStatus($task["dn"], $task["cn"][0], $mailSentResult[0]);
+      $result['Error']    = $mailSentResult;
+    }
 
-      return $result;
+    return $result;
   }
 
   /**
-- 
GitLab


From 13ff02260877f11f2789022966a782afda4ff67f Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:59:33 +0100
Subject: [PATCH 04/23] fix indent

---
 plugins/tasks/Mail.php | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index c2b4cf5..59890c7 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -110,8 +110,7 @@ class Mail implements EndpointInterface
   private function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
   {
       // Required before passing the array to the constructor mail.
-    if (empty($attachments))
-    {
+    if (empty($attachments)) {
       $attachments = NULL;
     }
 
@@ -127,7 +126,7 @@ class Mail implements EndpointInterface
       return $mail_controller->sendMail();
   }
 
-  private function updateResult(array $mailSentResult, $task, $fdTasksConf): array
+  private function updateResult (array $mailSentResult, $task, $fdTasksConf): array
   {
     $result = [];
     if ($mailSentResult[0] == "SUCCESS") {
-- 
GitLab


From d75a1a602173a5a62a19338fd4cb78b3e72dd888 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:01:11 +0100
Subject: [PATCH 05/23] fix indent

---
 plugins/tasks/Mail.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index 59890c7..612fd0f 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -92,6 +92,11 @@ class Mail implements EndpointInterface
             $attachments[]       = $fileInfo;
           }
 
+          // Required before passing the array to the constructor mail.
+          if (empty($attachments)) {
+            $attachments = NULL;
+          }
+
           $mailSentResult = $this->sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments);
           $result[$task["dn"]] = $this->updateResult($mailSentResult, $task, $fdTasksConf);
 
@@ -109,11 +114,6 @@ class Mail implements EndpointInterface
 
   private function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
   {
-      // Required before passing the array to the constructor mail.
-    if (empty($attachments)) {
-      $attachments = NULL;
-    }
-
     $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
       $setBCC,
       $recipients,
-- 
GitLab


From 296153c7a755ee68e0dd506faec2b15b08945622 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:05:43 +0100
Subject: [PATCH 06/23] Add mail utils

---
 library/MailUtils.php | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 library/MailUtils.php

diff --git a/library/MailUtils.php b/library/MailUtils.php
new file mode 100644
index 0000000..44b1f48
--- /dev/null
+++ b/library/MailUtils.php
@@ -0,0 +1,22 @@
+<?php
+
+class MailUtils
+{
+    private function __construct()
+    {
+    }
+
+    public static function sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
+    {
+        $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
+            $setBCC,
+            $recipients,
+            $body,
+            $signature,
+            $subject,
+            $receipt,
+            $attachments);
+
+        return $mail_controller->sendMail();
+    }
+}
\ No newline at end of file
-- 
GitLab


From adc4ed3e9e695881f5ba356f8dde6830e6c68e7b Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:06:40 +0100
Subject: [PATCH 07/23] use utils

---
 plugins/tasks/Mail.php | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index 612fd0f..2fcbe51 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -97,7 +97,7 @@ class Mail implements EndpointInterface
             $attachments = NULL;
           }
 
-          $mailSentResult = $this->sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments);
+          $mailSentResult = MailUtils::sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments);
           $result[$task["dn"]] = $this->updateResult($mailSentResult, $task, $fdTasksConf);
 
           // Verification anti-spam max mails to be sent and quit loop if matched
@@ -112,20 +112,6 @@ class Mail implements EndpointInterface
     return $result;
   }
 
-  private function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
-  {
-    $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
-      $setBCC,
-      $recipients,
-      $body,
-      $signature,
-      $subject,
-      $receipt,
-      $attachments);
-
-      return $mail_controller->sendMail();
-  }
-
   private function updateResult (array $mailSentResult, $task, $fdTasksConf): array
   {
     $result = [];
-- 
GitLab


From e3f0d89feb1732eda217e1583237fb9beee68120 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:10:44 +0100
Subject: [PATCH 08/23] add method

---
 library/MailUtils.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/library/MailUtils.php b/library/MailUtils.php
index 44b1f48..81eaa33 100644
--- a/library/MailUtils.php
+++ b/library/MailUtils.php
@@ -19,4 +19,16 @@ class MailUtils
 
         return $mail_controller->sendMail();
     }
+
+    /**
+     * @return array
+     * Note : A simple retrieval methods of the mail backend configuration set in FusionDirectory
+     */
+    public static function getMailObjectConfiguration (TaskGateway $gateway): array
+    {
+        return $gateway->getLdapTasks(
+            "(objectClass=fdTasksConf)",
+            ["fdTasksConfLastExecTime", "fdTasksConfIntervalEmails", "fdTasksConfMaxEmails"]
+        );
+    }
 }
\ No newline at end of file
-- 
GitLab


From c68a05bf74d6f385a2b17888cd73e87c7fe466b3 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:11:59 +0100
Subject: [PATCH 09/23] use utils

---
 plugins/tasks/Mail.php | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index 2fcbe51..2d29dc5 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -56,7 +56,7 @@ class Mail implements EndpointInterface
   public function processMailTasks (array $tasks): array
   {
     $result = [];
-    $fdTasksConf    = $this->getMailObjectConfiguration();
+    $fdTasksConf    = MailUtils::getMailObjectConfiguration($this->gateway);
     $maxMailsConfig = $this->returnMaximumMailToBeSend($fdTasksConf);
 
     // Increment for anti=spam, starts at 0, each mail task only contain one email, addition if simply + one.
@@ -129,17 +129,6 @@ class Mail implements EndpointInterface
     return $result;
   }
 
-  /**
-   * @return array
-   * Note : A simple retrieval methods of the mail backend configuration set in FusionDirectory
-   */
-  private function getMailObjectConfiguration (): array
-  {
-    return $this->gateway->getLdapTasks(
-      "(objectClass=fdTasksConf)",
-      ["fdTasksConfLastExecTime", "fdTasksConfIntervalEmails", "fdTasksConfMaxEmails"]
-    );
-  }
 
   /**
    * @param array $fdTasksConf
-- 
GitLab


From 6c989d3e2921b809105cb4283a67e65d31224b93 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:22:52 +0100
Subject: [PATCH 10/23] fix indent

---
 library/MailUtils.php | 52 +++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/library/MailUtils.php b/library/MailUtils.php
index 81eaa33..8779224 100644
--- a/library/MailUtils.php
+++ b/library/MailUtils.php
@@ -2,33 +2,33 @@
 
 class MailUtils
 {
-    private function __construct()
-    {
-    }
+  private function __construct()
+  {
+  }
 
-    public static function sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
-    {
-        $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
-            $setBCC,
-            $recipients,
-            $body,
-            $signature,
-            $subject,
-            $receipt,
-            $attachments);
+  public static function sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
+  {
+    $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
+      $setBCC,
+      $recipients,
+      $body,
+      $signature,
+      $subject,
+      $receipt,
+      $attachments);
 
-        return $mail_controller->sendMail();
-    }
+    return $mail_controller->sendMail();
+  }
 
-    /**
-     * @return array
-     * Note : A simple retrieval methods of the mail backend configuration set in FusionDirectory
-     */
-    public static function getMailObjectConfiguration (TaskGateway $gateway): array
-    {
-        return $gateway->getLdapTasks(
-            "(objectClass=fdTasksConf)",
-            ["fdTasksConfLastExecTime", "fdTasksConfIntervalEmails", "fdTasksConfMaxEmails"]
-        );
-    }
+  /**
+   * @return array
+   * Note : A simple retrieval methods of the mail backend configuration set in FusionDirectory
+   */
+  public static function getMailObjectConfiguration (TaskGateway $gateway): array
+  {
+    return $gateway->getLdapTasks(
+      "(objectClass=fdTasksConf)",
+      ["fdTasksConfLastExecTime", "fdTasksConfIntervalEmails", "fdTasksConfMaxEmails"]
+    );
+  }
 }
\ No newline at end of file
-- 
GitLab


From a2b22532ef326b90671b924313af70ecfc2e7e5a Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 13:23:22 +0100
Subject: [PATCH 11/23] fix indent

---
 library/MailUtils.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/library/MailUtils.php b/library/MailUtils.php
index 8779224..5fc496a 100644
--- a/library/MailUtils.php
+++ b/library/MailUtils.php
@@ -2,11 +2,11 @@
 
 class MailUtils
 {
-  private function __construct()
+  private function __construct ()
   {
   }
 
-  public static function sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
+  public static function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
   {
     $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
       $setBCC,
-- 
GitLab


From 00f0beb934bff1e438f01d8cebca78d7bb047611 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Tue, 25 Mar 2025 11:11:09 +0100
Subject: [PATCH 12/23] use maps

---
 library/Utils.php | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/library/Utils.php b/library/Utils.php
index 1c132ac..24e8309 100644
--- a/library/Utils.php
+++ b/library/Utils.php
@@ -13,20 +13,12 @@ class Utils
    */
   public static 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 = self::recursiveArrayFilter($item);
-        // Only retain non-empty arrays
-        return !empty($item);
-      } else {
-        // Retain non-empty scalar values
+    return array_filter($array, function ($item) {
+        if (is_array($item)) {
+            $item = self::recursiveArrayFilter($item);
+        }
         return !empty($item);
-      }
     });
-
-    return $filtered;
   }
 
   /**
@@ -40,12 +32,10 @@ class Utils
   {
     $matching = [];
 
-    if (!empty($elements)) {
-      foreach ($elements as $element) {
-        foreach ($keys as $key) {
-          if (!empty($element) && array_key_exists($key, $element)) {
-            $matching[] = $key;
-          }
+    foreach ($elements as $element) {
+      foreach ($keys as $key) {
+        if (!empty($element) && array_key_exists($key, $element)) {
+          $matching[] = $key;
         }
       }
     }
-- 
GitLab


From 6dea36ea14ff64cf12aefee091d1c939c6d29aa3 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Tue, 25 Mar 2025 11:12:26 +0100
Subject: [PATCH 13/23] indent

---
 library/Utils.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/library/Utils.php b/library/Utils.php
index 24e8309..7e31d9b 100644
--- a/library/Utils.php
+++ b/library/Utils.php
@@ -14,10 +14,10 @@ class Utils
   public static function recursiveArrayFilter (array $array): array
   {
     return array_filter($array, function ($item) {
-        if (is_array($item)) {
-            $item = self::recursiveArrayFilter($item);
-        }
-        return !empty($item);
+      if (is_array($item)) {
+          $item = self::recursiveArrayFilter($item);
+      }
+      return !empty($item);
     });
   }
 
-- 
GitLab


From 08b5fa47b5b5f20308cf34236bf616ed573efca4 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Tue, 25 Mar 2025 11:56:04 +0100
Subject: [PATCH 14/23] make non static

---
 library/Utils.php                             | 75 -------------------
 library/{ => plugins}/MailUtils.php           |  6 +-
 .../ReminderTokenUtils.php}                   | 40 ++++++----
 library/plugins/Utils.php                     | 59 +++++++++++++++
 plugins/tasks/Audit.php                       |  4 +-
 plugins/tasks/Notifications.php               |  6 +-
 plugins/tasks/Reminder.php                    | 16 ++--
 7 files changed, 103 insertions(+), 103 deletions(-)
 delete mode 100644 library/Utils.php
 rename library/{ => plugins}/MailUtils.php (70%)
 rename library/{TokenUtils.php => plugins/ReminderTokenUtils.php} (77%)
 create mode 100644 library/plugins/Utils.php

diff --git a/library/Utils.php b/library/Utils.php
deleted file mode 100644
index 7e31d9b..0000000
--- a/library/Utils.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-class Utils
-{
-  private function __construct ()
-  {
-  }
-
-  /**
-   * @param array $array
-   * @return array
-   * Note : Recursively filters out empty values and arrays at any depth.
-   */
-  public static function recursiveArrayFilter (array $array): array
-  {
-    return array_filter($array, function ($item) {
-      if (is_array($item)) {
-          $item = self::recursiveArrayFilter($item);
-      }
-      return !empty($item);
-    });
-  }
-
-  /**
-   * Find matching keys between 2 lists.
-   *
-   * @param array|null $elements
-   * @param array $keys
-   * @return array
-   */
-  public static function findMatchingKeys (?array $elements, array $keys): array
-  {
-    $matching = [];
-
-    foreach ($elements as $element) {
-      foreach ($keys as $key) {
-        if (!empty($element) && array_key_exists($key, $element)) {
-          $matching[] = $key;
-        }
-      }
-    }
-
-    return $matching;
-  }
-
-  /**
-   * @param $array
-   * @return array
-   * Note : simply return all values of a multi-dimensional array.
-   */
-  public static function getArrayValuesRecursive ($array)
-  {
-    $values = [];
-    foreach ($array as $value) {
-      if (is_array($value)) {
-        // If value is an array, merge its values recursively
-        $values = array_merge($values, self::getArrayValuesRecursive($value));
-      } else {
-        // If value is not an array, add it to the result
-        $values[] = $value;
-      }
-    }
-    return $values;
-  }
-
-  /**
-   * @param string $text
-   * @return string
-   * Note : This come from jwtToken, as it is completely private - it is cloned here for now.
-   */
-  public static function base64urlEncode (string $text): string
-  {
-    return str_replace(["+", "/", "="], ["A", "B", ""], base64_encode($text));
-  }
-}
\ No newline at end of file
diff --git a/library/MailUtils.php b/library/plugins/MailUtils.php
similarity index 70%
rename from library/MailUtils.php
rename to library/plugins/MailUtils.php
index 5fc496a..87f4c64 100644
--- a/library/MailUtils.php
+++ b/library/plugins/MailUtils.php
@@ -2,11 +2,11 @@
 
 class MailUtils
 {
-  private function __construct ()
+  public function __construct ()
   {
   }
 
-  public static function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
+  public function sendMail ($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments)
   {
     $mail_controller = new \FusionDirectory\Mail\MailLib($setFrom,
       $setBCC,
@@ -24,7 +24,7 @@ class MailUtils
    * @return array
    * Note : A simple retrieval methods of the mail backend configuration set in FusionDirectory
    */
-  public static function getMailObjectConfiguration (TaskGateway $gateway): array
+  public function getMailObjectConfiguration (TaskGateway $gateway): array
   {
     return $gateway->getLdapTasks(
       "(objectClass=fdTasksConf)",
diff --git a/library/TokenUtils.php b/library/plugins/ReminderTokenUtils.php
similarity index 77%
rename from library/TokenUtils.php
rename to library/plugins/ReminderTokenUtils.php
index 8552514..4ead9b4 100644
--- a/library/TokenUtils.php
+++ b/library/plugins/ReminderTokenUtils.php
@@ -1,8 +1,8 @@
 <?php
 
-class TokenUtils
+class ReminderTokenUtils
 {
-  private function __construct ()
+  public function __construct ()
   {
   }
 
@@ -12,7 +12,7 @@ class TokenUtils
    * @return string
    * @throws Exception
    */
-  public static function generateToken (string $userDN, int $timeStamp, TaskGateway $gateway): string
+  public function generateToken (string $userDN, int $timeStamp, TaskGateway $gateway): string
   {
     $token = NULL;
     // Salt has been generated with APG.
@@ -25,10 +25,10 @@ class TokenUtils
     $token_hmac = hash_hmac("sha256", $time . $payload, $_ENV["SECRET_KEY"], TRUE);
 
     // We need to have a token allowed to be used within an URL.
-    $token = Utils::base64urlEncode($token_hmac);
+    $token = $this->base64urlEncode($token_hmac);
 
     // Save token within LDAP
-    self::saveTokenInLdap($userDN, $token, $timeStamp, $gateway);
+    $this->saveTokenInLdap($userDN, $token, $timeStamp, $gateway);
 
     return $token;
   }
@@ -41,7 +41,7 @@ class TokenUtils
    * @return bool
    * @throws Exception
    */
-  public static function saveTokenInLdap (string $userDN, string $token, int $days, TaskGateway $gateway): bool
+  private function saveTokenInLdap (string $userDN, string $token, int $days, TaskGateway $gateway): bool
   {
     $result = FALSE;
 
@@ -64,17 +64,17 @@ class TokenUtils
 
 
     // Verify if token ou branch exists
-    if (!self::tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"], $gateway)) {
+    if (!$this->tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"], $gateway)) {
       // Create the branch
-      self::createBranchToken($gateway);
+      $this->createBranchToken($gateway);
     }
 
     // The user token DN creation
     $userTokenDN = 'cn=' . $uid . ',ou=tokens' . ',' . $_ENV["LDAP_BASE"];
     // Verify if a token already exists for specified user and remove it to create new one correctly.
-    if (self::tokenBranchExist($userTokenDN, $gateway)) {
+    if ($this->tokenBranchExist($userTokenDN, $gateway)) {
       // Remove the user token
-      self::removeUserToken($userTokenDN, $gateway);
+      $this->removeUserToken($userTokenDN, $gateway);
     }
 
     // Add token to LDAP for specific UID
@@ -95,7 +95,7 @@ class TokenUtils
    * @return int
    * Note : Simply return the difference between first and second call. (First call can be null).
    */
-  public static function getTokenExpiration (int $subTaskCall, int $firstCall, int $secondCall): int
+  public function getTokenExpiration (int $subTaskCall, int $firstCall, int $secondCall): int
   {
     // if firstCall is empty, secondCall is the timestamp expiry for the token.
     $result = $secondCall;
@@ -115,7 +115,7 @@ class TokenUtils
    * @return void
    * Note : Simply remove the token for specific user DN
    */
-  public static function removeUserToken ($userTokenDN, TaskGateway $gateway): void
+  private function removeUserToken ($userTokenDN, TaskGateway $gateway): void
   {
     // Add token to LDAP for specific UID
     try {
@@ -130,7 +130,7 @@ class TokenUtils
    * Create ou=pluginManager LDAP branch
    * @throws Exception
    */
-  public static function createBranchToken (TaskGateway $gateway): void
+  private function createBranchToken (TaskGateway $gateway): void
   {
     try {
       ldap_add(
@@ -153,7 +153,7 @@ class TokenUtils
    * @param string $taskDN
    * @return array
    */
-  public static function generateTokenUrl (string $token, array $mailTemplateForm, string $taskDN): array
+  public function generateTokenUrl (string $token, array $mailTemplateForm, string $taskDN): array
   {
     //Only take the cn of the main task name :
     preg_match('/cn=([^,]+),ou=/', $taskDN, $matches);
@@ -173,7 +173,7 @@ class TokenUtils
    * @return bool
    * Note : Simply inspect if the branch for token is existing.
    */
-  public static function tokenBranchExist (string $dn, TaskGateway $gateway): bool
+  private function tokenBranchExist (string $dn, TaskGateway $gateway): bool
   {
     $result = FALSE;
 
@@ -195,4 +195,14 @@ class TokenUtils
 
     return $result;
   }
+
+    /**
+     * @param string $text
+     * @return string
+     * Note : This come from jwtToken, as it is completely private - it is cloned here for now.
+     */
+    private function base64urlEncode (string $text): string
+    {
+        return str_replace(["+", "/", "="], ["A", "B", ""], base64_encode($text));
+    }
 }
\ No newline at end of file
diff --git a/library/plugins/Utils.php b/library/plugins/Utils.php
new file mode 100644
index 0000000..10eafe6
--- /dev/null
+++ b/library/plugins/Utils.php
@@ -0,0 +1,59 @@
+<?php
+
+class Utils
+{
+  public function __construct ()
+  {
+  }
+
+  /**
+   * @param array $array
+   * @return array
+   * Note : Recursively filters out empty values and arrays at any depth.
+   */
+  public function recursiveArrayFilter (array $array): array
+  {
+    return array_filter($array, function ($item) {
+      if (is_array($item)) {
+          $item = $this->recursiveArrayFilter($item);
+      }
+      return !empty($item);
+    });
+  }
+
+  /**
+   * Find matching keys between 2 lists.
+   *
+   * @param array|null $elements
+   * @param array $keys
+   * @return array
+   */
+  public function findMatchingKeys (?array $elements, array $keys): array
+  {
+    $matching = [];
+
+    if (!empty($elements)) {
+      foreach ($elements as $element) {
+        foreach ($keys as $key) {
+          if (!empty($element) && array_key_exists($key, $element)) {
+            $matching[] = $key;
+          }
+        }
+      }
+    }
+
+    return $matching;
+  }
+
+  /**
+   * @param $array
+   * @return array
+   * Note : simply return all values of a multi-dimensional array.
+   */
+  public function getArrayValuesRecursive ($array)
+  {
+    return array_reduce($array, function ($carry, $value) {
+      return array_merge($carry, is_array($value) ? $this->getArrayValuesRecursive($value) : [$value]);
+    }, []);
+  }
+}
\ No newline at end of file
diff --git a/plugins/tasks/Audit.php b/plugins/tasks/Audit.php
index c4bbe40..9481831 100644
--- a/plugins/tasks/Audit.php
+++ b/plugins/tasks/Audit.php
@@ -4,10 +4,12 @@ class Audit implements EndpointInterface
 {
 
   private TaskGateway $gateway;
+  private Utils $utils;
 
   public function __construct (TaskGateway $gateway)
   {
     $this->gateway = $gateway;
+    $this->utils = new Utils();
   }
 
   /**
@@ -47,7 +49,7 @@ class Audit implements EndpointInterface
     $result = $this->processAuditDeletion($this->gateway->getObjectTypeTask('Audit'));
 
     // Recursive function to filter out empty arrays at any depth
-    $nonEmptyResults = Utils::recursiveArrayFilter($result);
+    $nonEmptyResults = $this->utils->recursiveArrayFilter($result);
 
     if (!empty($nonEmptyResults)) {
       return $nonEmptyResults;
diff --git a/plugins/tasks/Notifications.php b/plugins/tasks/Notifications.php
index e17ffe3..4547b87 100644
--- a/plugins/tasks/Notifications.php
+++ b/plugins/tasks/Notifications.php
@@ -4,10 +4,12 @@ class Notifications implements EndpointInterface
 {
 
   private TaskGateway $gateway;
+  private Utils $utils;
 
   public function __construct (TaskGateway $gateway)
   {
     $this->gateway = $gateway;
+    $this->utils = new Utils();
   }
 
   /**
@@ -82,7 +84,7 @@ class Notifications implements EndpointInterface
         $this->gateway->unsetCountKeys($monitoredSupannResource);
 
         // Find matching attributes between audited and monitored attributes
-        $matchingAttrs = Utils::findMatchingKeys($auditAttributes, $monitoredAttrs);
+        $matchingAttrs = $this->utils->findMatchingKeys($auditAttributes, $monitoredAttrs);
 
         // Verify Supann resource state if applicable
         if ($this->shouldVerifySupannResource($monitoredSupannResource, $auditAttributes)) {
@@ -183,7 +185,7 @@ class Notifications implements EndpointInterface
     }
 
     // Get all the values only of a multidimensional array.
-    $auditedValues = Utils::getArrayValuesRecursive($auditedAttrs);
+    $auditedValues = $this->utils->getArrayValuesRecursive($auditedAttrs);
 
     if (in_array($monitoredSupannState, $auditedValues)) {
       $result = TRUE;
diff --git a/plugins/tasks/Reminder.php b/plugins/tasks/Reminder.php
index 1faeff7..ceb619a 100644
--- a/plugins/tasks/Reminder.php
+++ b/plugins/tasks/Reminder.php
@@ -4,10 +4,12 @@ class Reminder implements EndpointInterface
 {
 
   private TaskGateway $gateway;
-
+  private ReminderTokenUtils $reminderTokenUtils;
+  
   public function __construct (TaskGateway $gateway)
   {
     $this->gateway = $gateway;
+    $this->reminderTokenUtils = new ReminderTokenUtils();
   }
 
   /**
@@ -109,13 +111,13 @@ class Reminder implements EndpointInterface
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['uid'] = $task['fdtasksgranulardn'][0];
 
             // Create timeStamp expiration for token
-            $tokenExpire = TokenUtils::getTokenExpiration($task['fdtasksgranularhelper'][0],
+            $tokenExpire = $this->reminderTokenUtils->getTokenExpiration($task['fdtasksgranularhelper'][0],
               $remindersMainTask[0]['fdtasksreminderfirstcall'][0],
               $remindersMainTask[0]['fdtasksremindersecondcall'][0]);
             // Create token for SubTask
-            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire, $this->gateway);
+            $token = $this->reminderTokenUtils->generateToken($task['fdtasksgranulardn'][0], $tokenExpire, $this->gateway);
             // Edit the mailForm with the url link containing the token
-            $tokenMailTemplateForm = TokenUtils::generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
+            $tokenMailTemplateForm = $this->reminderTokenUtils->generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
             // Recipient email form
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['mail'] = $tokenMailTemplateForm;
 
@@ -136,13 +138,13 @@ class Reminder implements EndpointInterface
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['uid'] = $task['fdtasksgranulardn'][0];
 
             // Create timeStamp expiration for token
-            $tokenExpire = TokenUtils::getTokenExpiration($task['fdtasksgranularhelper'][0],
+            $tokenExpire = $this->reminderTokenUtils->getTokenExpiration($task['fdtasksgranularhelper'][0],
               $remindersMainTask[0]['fdtasksreminderfirstcall'][0],
               $remindersMainTask[0]['fdtasksremindersecondcall'][0]);
             // Create token for SubTask
-            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire, $this->gateway);
+            $token = $this->reminderTokenUtils->generateToken($task['fdtasksgranulardn'][0], $tokenExpire, $this->gateway);
             // Edit the mailForm with the url link containing the token
-            $tokenMailTemplateForm = TokenUtils::generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
+            $tokenMailTemplateForm = $this->reminderTokenUtils->generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
             // Recipient email form
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['mail'] = $tokenMailTemplateForm;
 
-- 
GitLab


From 7bf59a638a5198858ba048975ac7d530752ab320 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Tue, 25 Mar 2025 11:57:20 +0100
Subject: [PATCH 15/23] fix indent

---
 library/plugins/ReminderTokenUtils.php | 18 +++++++++---------
 plugins/tasks/Reminder.php             |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/library/plugins/ReminderTokenUtils.php b/library/plugins/ReminderTokenUtils.php
index 4ead9b4..bb08d24 100644
--- a/library/plugins/ReminderTokenUtils.php
+++ b/library/plugins/ReminderTokenUtils.php
@@ -196,13 +196,13 @@ class ReminderTokenUtils
     return $result;
   }
 
-    /**
-     * @param string $text
-     * @return string
-     * Note : This come from jwtToken, as it is completely private - it is cloned here for now.
-     */
-    private function base64urlEncode (string $text): string
-    {
-        return str_replace(["+", "/", "="], ["A", "B", ""], base64_encode($text));
-    }
+  /**
+   * @param string $text
+   * @return string
+   * Note : This come from jwtToken, as it is completely private - it is cloned here for now.
+   */
+  private function base64urlEncode (string $text): string
+  {
+    return str_replace(["+", "/", "="], ["A", "B", ""], base64_encode($text));
+  }
 }
\ No newline at end of file
diff --git a/plugins/tasks/Reminder.php b/plugins/tasks/Reminder.php
index ceb619a..180eca7 100644
--- a/plugins/tasks/Reminder.php
+++ b/plugins/tasks/Reminder.php
@@ -5,7 +5,7 @@ class Reminder implements EndpointInterface
 
   private TaskGateway $gateway;
   private ReminderTokenUtils $reminderTokenUtils;
-  
+
   public function __construct (TaskGateway $gateway)
   {
     $this->gateway = $gateway;
-- 
GitLab


From f62bb3d3742c04c27e3f88a5795f9bc1d812ca5b Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Thu, 27 Mar 2025 14:14:24 +0100
Subject: [PATCH 16/23] use utils

---
 plugins/tasks/Mail.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/plugins/tasks/Mail.php b/plugins/tasks/Mail.php
index 2d29dc5..5afe7ac 100644
--- a/plugins/tasks/Mail.php
+++ b/plugins/tasks/Mail.php
@@ -4,10 +4,12 @@
 class Mail implements EndpointInterface
 {
   private TaskGateway $gateway;
+  private MailUtils $mailUtils;
 
   function __construct (TaskGateway $gateway)
   {
     $this->gateway = $gateway;
+    $this->mailUtils = new MailUtils();
   }
 
   /**
@@ -56,7 +58,7 @@ class Mail implements EndpointInterface
   public function processMailTasks (array $tasks): array
   {
     $result = [];
-    $fdTasksConf    = MailUtils::getMailObjectConfiguration($this->gateway);
+    $fdTasksConf    = $this->mailUtils->getMailObjectConfiguration($this->gateway);
     $maxMailsConfig = $this->returnMaximumMailToBeSend($fdTasksConf);
 
     // Increment for anti=spam, starts at 0, each mail task only contain one email, addition if simply + one.
@@ -97,7 +99,7 @@ class Mail implements EndpointInterface
             $attachments = NULL;
           }
 
-          $mailSentResult = MailUtils::sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments);
+          $mailSentResult = $this->mailUtils->sendMail($setFrom, $setBCC, $recipients, $body, $signature, $subject, $receipt, $attachments);
           $result[$task["dn"]] = $this->updateResult($mailSentResult, $task, $fdTasksConf);
 
           // Verification anti-spam max mails to be sent and quit loop if matched
-- 
GitLab


From 04ca3d95003ea085f573c9839de9068d86039d82 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Mon, 24 Mar 2025 10:46:00 +0000
Subject: [PATCH 17/23] :sparkles: Feat(gateway) - simply add gateway to get
 methods

---
 .gitignore                 | 7 +++++++
 library/TaskController.php | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index a474600..84558c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,9 @@
 .vendor/
 .composer.lock
+filelist
+phpstan.neon
+.idea/fusiondirectory-orchestrator.iml
+.idea/modules.xml
+.idea/php.xml
+.idea/vcs.xml
+.idea/codeStyles/codeStyleConfig.xml
diff --git a/library/TaskController.php b/library/TaskController.php
index 849f5b6..2b4ddf3 100644
--- a/library/TaskController.php
+++ b/library/TaskController.php
@@ -55,7 +55,7 @@ class TaskController
           switch ($objectType) {
             case $objectType:
               if (class_exists($objectType)) {
-                $endpoint = new $objectType;
+                $endpoint = new $objectType($this->gateway);
                 $result   = $endpoint->processEndPointGet();
               }
               break;
-- 
GitLab


From 7185c413c350cea09ec65f15b8a8fe358065dd08 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Mon, 24 Mar 2025 15:21:23 +0000
Subject: [PATCH 18/23] :sparkles: feat(archive) - implement Archive endpoint
 with GET, PATCH, POST, and DELETE methods

---
 plugins/tasks/Archive.php | 98 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 plugins/tasks/Archive.php

diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php
new file mode 100644
index 0000000..e7838f8
--- /dev/null
+++ b/plugins/tasks/Archive.php
@@ -0,0 +1,98 @@
+<?php
+
+class Archive implements EndpointInterface
+{
+  private TaskGateway $gateway;
+
+  public function __construct(TaskGateway $gateway)
+  {
+    $this->gateway = $gateway;
+  }
+
+  /**
+   * @return array
+   * Part of the interface of orchestrator plugin to treat GET method
+   */
+  public function processEndPointGet(): array
+  {
+    // Retrieve tasks of type 'archive'
+    return $this->gateway->getObjectTypeTask('archive');
+  }
+
+  /**
+   * @param array|null $data
+   * @return array
+   * @throws Exception
+   * Note: Part of the interface of orchestrator plugin to treat PATCH method
+   */
+  public function processEndPointPatch(array $data = NULL): array
+  {
+    $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)) {
+        // Retrieve the user's supannAccountStatus
+        $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]);
+
+          // Update the task status based on the result
+          if ($archiveResult === 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
+          }
+        } else {
+          $result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
+        }
+      }
+    }
+
+    return $result;
+  }
+
+  /**
+   * @param array|null $data
+   * @return array
+   * Note: Part of the interface of orchestrator plugin to treat POST method
+   */
+  public function processEndPointPost(array $data = NULL): array
+  {
+    return [];
+  }
+
+  /**
+   * @param array|null $data
+   * @return array
+   * Note: Part of the interface of orchestrator plugin to treat DELETE method
+   */
+  public function processEndPointDelete(array $data = NULL): array
+  {
+    return [];
+  }
+
+  /**
+   * Retrieve the supannAccountStatus of a user
+   * @param string $userDn
+   * @return string|null
+   */
+  private function getUserSupannAccountStatus(string $userDn): ?string
+  {
+    // Logic to retrieve the supannAccountStatus attribute of the user
+    $user = $this->gateway->getLdapEntry($userDn, ['supannAccountStatus']);
+    return $user['supannAccountStatus'][0] ?? NULL;
+  }
+}
\ No newline at end of file
-- 
GitLab


From e25902663885f92140ab6d6c9923dda29ba3b51b Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Mon, 24 Mar 2025 16:44:58 +0000
Subject: [PATCH 19/23] :sparkles: feat(archive) - enhance Archive
 functionality with WebServiceCall integration and improved error handling

---
 .idea/.gitignore          |  8 ++++++++
 plugins/tasks/Archive.php | 30 ++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 10 deletions(-)
 create mode 100755 .idea/.gitignore

diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100755
index 0000000..13566b8
--- /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 e7838f8..77492f8 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.";
         }
-- 
GitLab


From a37cd76cd9c11aaa1c0ada3ed42b656389f47400 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Tue, 25 Mar 2025 00:40:12 +0000
Subject: [PATCH 20/23] :sparkles: feat(archive) - refactor archiving logic to
 streamline user status checks and enhance error handling (still error from
 API)

---
 plugins/tasks/Archive.php | 107 ++++++++++++++++++++++++--------------
 1 file changed, 69 insertions(+), 38 deletions(-)

diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php
index 77492f8..f2bd8fb 100644
--- a/plugins/tasks/Archive.php
+++ b/plugins/tasks/Archive.php
@@ -32,43 +32,45 @@ class Archive implements EndpointInterface
     $result = [];
     $archiveTasks = $this->gateway->getObjectTypeTask('archive');
 
-    foreach ($archiveTasks as $task) {
-      // Verify the task status and schedule
-      if ($this->gateway->statusAndScheduleCheck($task)) {
-        // Retrieve the user's supannAccountStatus
-        $userStatus = $this->getUserSupannAccountStatus($task['fdtasksgranulardn'][0]);
-
-        // Check if the user meets the "toBeArchived" condition
-        if ($userStatus === 'toBeArchived') {
-          // 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();
-
-          // 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
-          }
+    // Initialize the WebServiceCall object for login
+    $webServiceCall = new WebServiceCall($_ENV['FUSION_DIRECTORY_API_URL'] . '/login', 'POST');
+    $webServiceCall->setCurlSettings(); // Perform login and set the token
 
-          // Close the cURL resource
-          curl_close($webServiceCall->ch);
-        } else {
-          $result[$task['dn']]['result'] = "User does not meet the criteria for archiving.";
+    foreach ($archiveTasks as $task) {
+        try {
+            if (!$this->gateway->statusAndScheduleCheck($task)) {
+                // Skip this task if it does not meet the status and schedule criteria
+                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, [], 'POST'); // Update settings for the archive request
+            $response = $webServiceCall->execute();
+
+            print_r([$response]);
+              exit;
+
+            if (isset($response['success']) && $response['success'] === true) {
+                $result[$task['dn']]['result'] = "User successfully archived.";
+                $this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], '2');
+            } else {
+                throw new Exception("Invalid API response format");
+            }
+        } catch (Exception $e) {
+            $result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
+            $this->gateway->updateTaskStatus($task['dn'], $task['cn'][0], $e->getMessage());
         }
-      }
     }
 
     return $result;
@@ -101,8 +103,37 @@ class Archive implements EndpointInterface
    */
   private function getUserSupannAccountStatus(string $userDn): ?string
   {
-    // Logic to retrieve the supannAccountStatus attribute of the user
-    $user = $this->gateway->getLdapEntry($userDn, ['supannAccountStatus']);
-    return $user['supannAccountStatus'][0] ?? NULL;
+      $supannState = $this->gateway->getLdapTasks(
+          '(objectClass=supannPerson)',
+          ['supannRessourceEtatDate'],
+          '',
+          $userDn
+      );
+  
+      if ($this->hasToBeArchived($supannState)) {
+          return 'toBeArchived';
+      }
+  
+      return null;
+  }
+
+  private function hasToBeArchived(array $supannState): bool
+  {
+      if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) {
+          return false;
+      }
+
+      foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) {
+          // Skip non-numeric keys (e.g., 'count')
+          if (!is_numeric($key)) {
+              continue;
+          }
+
+          if (strpos($value, '{COMPTE}I:toBeArchived') !== false) {
+              return true;
+          }
+      }
+
+      return false;
   }
 }
\ No newline at end of file
-- 
GitLab


From 867dbe15a94eb886ccf6cfdde6e1dfa3fd70e931 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Tue, 25 Mar 2025 11:57:08 +0000
Subject: [PATCH 21/23] :sparkles: feat(archive) - update archive request
 settings and improve error handling for unexpected HTTP status codes

---
 plugins/tasks/Archive.php | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php
index f2bd8fb..593c99d 100644
--- a/plugins/tasks/Archive.php
+++ b/plugins/tasks/Archive.php
@@ -55,17 +55,15 @@ class Archive implements EndpointInterface
 
             // 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, [], 'POST'); // Update settings for the archive request
+            $webServiceCall->setCurlSettings($archiveUrl, NULL, 'POST'); // Update settings for the archive request
             $response = $webServiceCall->execute();
 
-            print_r([$response]);
-              exit;
-
-            if (isset($response['success']) && $response['success'] === true) {
+            // 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("Invalid API response format");
+                throw new Exception("Unexpected HTTP status code: " . $webServiceCall->getHttpStatusCode());
             }
         } catch (Exception $e) {
             $result[$task['dn']]['result'] = "Error archiving user: " . $e->getMessage();
-- 
GitLab


From 1ca9fdf467596525204060826085b1b56f7ee41f Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Tue, 25 Mar 2025 15:17:33 +0000
Subject: [PATCH 22/23] :art: style(archive) - apply consistent spacing in
 method signatures and improve code readability

---
 plugins/tasks/Archive.php | 112 +++++++++++++++++++-------------------
 1 file changed, 56 insertions(+), 56 deletions(-)

diff --git a/plugins/tasks/Archive.php b/plugins/tasks/Archive.php
index 593c99d..2ef3e2f 100644
--- a/plugins/tasks/Archive.php
+++ b/plugins/tasks/Archive.php
@@ -6,7 +6,7 @@ class Archive implements EndpointInterface
 {
   private TaskGateway $gateway;
 
-  public function __construct(TaskGateway $gateway)
+  public function __construct (TaskGateway $gateway)
   {
     $this->gateway = $gateway;
   }
@@ -15,7 +15,7 @@ class Archive implements EndpointInterface
    * @return array
    * Part of the interface of orchestrator plugin to treat GET method
    */
-  public function processEndPointGet(): array
+  public function processEndPointGet (): array
   {
     // Retrieve tasks of type 'archive'
     return $this->gateway->getObjectTypeTask('archive');
@@ -27,7 +27,7 @@ class Archive implements EndpointInterface
    * @throws Exception
    * 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 = [];
     $archiveTasks = $this->gateway->getObjectTypeTask('archive');
@@ -37,38 +37,38 @@ class Archive implements EndpointInterface
     $webServiceCall->setCurlSettings(); // Perform login and set the token
 
     foreach ($archiveTasks as $task) {
-        try {
-            if (!$this->gateway->statusAndScheduleCheck($task)) {
-                // Skip this task if it does not meet the status and schedule criteria
-                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());
+      try {
+        if (!$this->gateway->statusAndScheduleCheck($task)) {
+            // Skip this task if it does not meet the status and schedule criteria
+            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());
+      }
     }
 
     return $result;
@@ -79,7 +79,7 @@ class Archive implements EndpointInterface
    * @return array
    * 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 [];
   }
@@ -89,7 +89,7 @@ class Archive implements EndpointInterface
    * @return array
    * 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 [];
   }
@@ -99,7 +99,7 @@ class Archive implements EndpointInterface
    * @param string $userDn
    * @return string|null
    */
-  private function getUserSupannAccountStatus(string $userDn): ?string
+  private function getUserSupannAccountStatus (string $userDn): ?string
   {
       $supannState = $this->gateway->getLdapTasks(
           '(objectClass=supannPerson)',
@@ -107,31 +107,31 @@ class Archive implements EndpointInterface
           '',
           $userDn
       );
-  
-      if ($this->hasToBeArchived($supannState)) {
-          return 'toBeArchived';
-      }
-  
-      return null;
+
+    if ($this->hasToBeArchived($supannState)) {
+        return 'toBeArchived';
+    }
+
+      return NULL;
   }
 
-  private function hasToBeArchived(array $supannState): bool
+  private function hasToBeArchived (array $supannState): bool
   {
-      if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) {
-          return false;
-      }
+    if (!isset($supannState[0]['supannressourceetatdate']) || !is_array($supannState[0]['supannressourceetatdate'])) {
+        return FALSE;
+    }
 
-      foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) {
-          // Skip non-numeric keys (e.g., 'count')
-          if (!is_numeric($key)) {
-              continue;
-          }
+    foreach ($supannState[0]['supannressourceetatdate'] as $key => $value) {
+        // Skip non-numeric keys (e.g., 'count')
+      if (!is_numeric($key)) {
+          continue;
+      }
 
-          if (strpos($value, '{COMPTE}I:toBeArchived') !== false) {
-              return true;
-          }
+      if (strpos($value, '{COMPTE}I:toBeArchived') !== FALSE) {
+          return TRUE;
       }
+    }
 
-      return false;
+      return FALSE;
   }
 }
\ No newline at end of file
-- 
GitLab


From bf4aa99d7ae7b5e1f301db1371f95a3a61dcbd87 Mon Sep 17 00:00:00 2001
From: Benoit Mortier <benoit.mortier@fusiondirectory.org>
Date: Tue, 25 Mar 2025 18:11:35 +0100
Subject: [PATCH 23/23] :ambulance: fix(centos) remove centos from the builds

Signed-off-by: Benoit Mortier <benoit.mortier@fusiondirectory.org>
---
 .gitlab-ci.yml | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1e84902..8356ce6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -93,10 +93,3 @@ trigger-ci-ubuntu-focal:
     project: ubuntu/focal-fusiondirectory-orchestrator-dev
     branch: "main"
 
-trigger-ci-centos-7:
-  stage: trigger
-  only:
-    - dev
-  trigger:
-    project: centos/centos7-fusiondirectory-orchestrator-dev
-    branch: "main"
-- 
GitLab