From bb5dfd5fba0bf029b1c88ff77255dc28412c28e0 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:08:50 +0100
Subject: [PATCH 01/22] Refactor libraries

---
 library/TokenUtils.php          | 197 +++++++++++++++++++++++++++
 library/Utils.php               |  83 ++++++++++++
 plugins/tasks/Audit.php         |  25 +---
 plugins/tasks/Notifications.php |  48 +------
 plugins/tasks/Reminder.php      | 233 +-------------------------------
 5 files changed, 289 insertions(+), 297 deletions(-)
 create mode 100644 library/TokenUtils.php
 create mode 100644 library/Utils.php

diff --git a/library/TokenUtils.php b/library/TokenUtils.php
new file mode 100644
index 0000000..d19392c
--- /dev/null
+++ b/library/TokenUtils.php
@@ -0,0 +1,197 @@
+<?php
+
+class TokenUtils
+{
+    private function __construct() {
+    }
+
+    /**
+     * @param string $userDN
+     * @param int $timeStamp
+     * @return string
+     * @throws Exception
+     */
+    public static function generateToken (string $userDN, int $timeStamp): string
+    {
+        $token = NULL;
+        // Salt has been generated with APG.
+        $salt    = '8onOlEsItKond';
+        $payload = json_encode($userDN . $salt);
+        // This allows the token to be different every time.
+        $time = time();
+
+        // Create hmac with sha256 alg and the key provided for JWT token signature in ENV.
+        $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);
+
+        // Save token within LDAP
+        self::saveTokenInLdap($userDN, $token, $timeStamp);
+
+        return $token;
+    }
+
+    /**
+     * @param string $userDN
+     * @param string $token
+     * NOTE : UID is the full DN of the user. (uid=...).
+     * @param int $days
+     * @return bool
+     * @throws Exception
+     */
+    public static function saveTokenInLdap (string $userDN, string $token, int $days, TaskGateway $gateway): bool
+    {
+        $result = FALSE;
+
+        $currentTimestamp = time();
+        // Calculate the future timestamp by adding days to the current timestamp (We actually adds number of seconds).
+        $futureTimestamp = $currentTimestamp + ($days * 24 * 60 * 60);
+
+        preg_match('/uid=([^,]+),ou=/', $userDN, $matches);
+        $uid = $matches[1];
+        $dn  = 'cn=' . $uid . ',' . 'ou=tokens' . ',' . $_ENV["LDAP_BASE"];
+
+        $ldap_entry["objectClass"]      = ['top', 'fdTokenEntry'];
+        $ldap_entry["fdTokenUserDN"]    = $userDN;
+        $ldap_entry["fdTokenType"]      = 'reminder';
+        $ldap_entry["fdToken"]          = $token;
+        $ldap_entry["fdTokenTimestamp"] = $futureTimestamp;
+        $ldap_entry["cn"]               = $uid;
+
+        // set the dn for the token, only take what's between "uid=" and ",ou="
+
+
+        // Verify if token ou branch exists
+        if (!self::tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"])) {
+            // Create the branch
+            self::createBranchToken();
+        }
+
+        // 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)) {
+            // Remove the user token
+            self::removeUserToken($userTokenDN);
+        }
+
+        // Add token to LDAP for specific UID
+        try {
+            $result = ldap_add($gateway->ds, $dn, $ldap_entry); // bool returned
+        } catch (Exception $e) {
+            echo json_encode(["Ldap Error - Token could not be saved!" => "$e"]); // string returned
+            exit;
+        }
+
+        return $result;
+    }
+
+    /**
+     * @param int $subTaskCall
+     * @param int $firstCall
+     * @param int $secondCall
+     * @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
+    {
+        // if firstCall is empty, secondCall is the timestamp expiry for the token.
+        $result = $secondCall;
+
+        if (!empty($firstCall)) {
+            // Verification if the subTask is the second reminder or the first reminder.
+            if ($subTaskCall === $firstCall) {
+                $result = $firstCall - $secondCall;
+            }
+        }
+
+        return $result;
+    }
+
+    /**
+     * @param $userTokenDN
+     * @return void
+     * Note : Simply remove the token for specific user DN
+     */
+    public static function removeUserToken ($userTokenDN, TaskGateway $gateway): void
+    {
+        // Add token to LDAP for specific UID
+        try {
+            $result = ldap_delete($gateway->ds, $userTokenDN); // bool returned
+        } catch (Exception $e) {
+            echo json_encode(["Ldap Error - User token could not be removed!" => "$e"]); // string returned
+            exit;
+        }
+    }
+
+    /**
+     * Create ou=pluginManager LDAP branch
+     * @throws Exception
+     */
+    public static function createBranchToken (TaskGateway $gateway): void
+    {
+        try {
+            ldap_add(
+                $gateway->ds, 'ou=tokens' . ',' . $_ENV["LDAP_BASE"],
+                [
+                    'ou'          => 'tokens',
+                    'objectClass' => 'organizationalUnit',
+                ]
+            );
+        } catch (Exception $e) {
+
+            echo json_encode(["Ldap Error - Impossible to create the token branch" => "$e"]); // string returned
+            exit;
+        }
+    }
+
+    /**
+     * @param string $token
+     * @param array $mailTemplateForm
+     * @param string $taskDN
+     * @return array
+     */
+    public static function generateTokenUrl (string $token, array $mailTemplateForm, string $taskDN): array
+    {
+        //Only take the cn of the main task name :
+        preg_match('/cn=([^,]+),ou=/', $taskDN, $matches);
+        $taskName = $matches[1];
+
+        // Remove the API URI
+        $cleanedUrl = preg_replace('#/rest\.php/v1$#', '', $_ENV['FUSION_DIRECTORY_API_URL']);
+        $url        = $cleanedUrl . '/accountProlongation.php?token=' . $token . '&task=' . $taskName;
+
+        $mailTemplateForm['body'] .= $url;
+
+        return $mailTemplateForm;
+    }
+
+    /**
+     * @param string $dn
+     * @return bool
+     * Note : Simply inspect if the branch for token is existing.
+     */
+    public static function tokenBranchExist (string $dn, TaskGateway $gateway): bool
+    {
+        $result = FALSE;
+
+        try {
+            $search = ldap_search($gateway->ds, $dn, "(objectClass=*)");
+            // Check if the search was successful
+            if ($search) {
+                // Get the number of entries found
+                $entries = ldap_get_entries($gateway->ds, $search);
+
+                // If entries are found, set result to true
+                if ($entries["count"] > 0) {
+                    $result = TRUE;
+                }
+            }
+        } catch (Exception $e) {
+            $result = FALSE;
+        }
+
+        return $result;
+    }
+}
\ No newline at end of file
diff --git a/library/Utils.php b/library/Utils.php
new file mode 100644
index 0000000..c241a0a
--- /dev/null
+++ b/library/Utils.php
@@ -0,0 +1,83 @@
+<?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
+    {
+        // 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;
+    }
+
+    /**
+     * 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 = [];
+
+        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 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/plugins/tasks/Audit.php b/plugins/tasks/Audit.php
index 6e51ae7..c4bbe40 100644
--- a/plugins/tasks/Audit.php
+++ b/plugins/tasks/Audit.php
@@ -47,7 +47,7 @@ class Audit implements EndpointInterface
     $result = $this->processAuditDeletion($this->gateway->getObjectTypeTask('Audit'));
 
     // Recursive function to filter out empty arrays at any depth
-    $nonEmptyResults = $this->recursiveArrayFilter($result);
+    $nonEmptyResults = Utils::recursiveArrayFilter($result);
 
     if (!empty($nonEmptyResults)) {
       return $nonEmptyResults;
@@ -119,27 +119,4 @@ class Audit implements EndpointInterface
 
     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
diff --git a/plugins/tasks/Notifications.php b/plugins/tasks/Notifications.php
index f78ef5e..e17ffe3 100644
--- a/plugins/tasks/Notifications.php
+++ b/plugins/tasks/Notifications.php
@@ -82,7 +82,7 @@ class Notifications implements EndpointInterface
         $this->gateway->unsetCountKeys($monitoredSupannResource);
 
         // Find matching attributes between audited and monitored attributes
-        $matchingAttrs = $this->findMatchingAttributes($auditAttributes, $monitoredAttrs);
+        $matchingAttrs = Utils::findMatchingKeys($auditAttributes, $monitoredAttrs);
 
         // Verify Supann resource state if applicable
         if ($this->shouldVerifySupannResource($monitoredSupannResource, $auditAttributes)) {
@@ -165,30 +165,6 @@ class Notifications implements EndpointInterface
     return $auditAttributes;
   }
 
-  /**
-   * Find matching attributes between audit and monitored attributes.
-   *
-   * @param array|null $auditAttributes
-   * @param array $monitoredAttrs
-   * @return array
-   */
-  private function findMatchingAttributes (?array $auditAttributes, array $monitoredAttrs): array
-  {
-    $matchingAttrs = [];
-
-    if (!empty($auditAttributes)) {
-      foreach ($auditAttributes as $attributeName) {
-        foreach ($monitoredAttrs as $monitoredAttr) {
-          if (!empty($attributeName) && array_key_exists($monitoredAttr, $attributeName)) {
-            $matchingAttrs[] = $monitoredAttr;
-          }
-        }
-      }
-    }
-
-    return $matchingAttrs;
-  }
-
   /**
    * @param array $supannResource
    * @param array $auditedAttrs
@@ -207,7 +183,7 @@ class Notifications implements EndpointInterface
     }
 
     // Get all the values only of a multidimensional array.
-    $auditedValues = $this->getArrayValuesRecursive($auditedAttrs);
+    $auditedValues = Utils::getArrayValuesRecursive($auditedAttrs);
 
     if (in_array($monitoredSupannState, $auditedValues)) {
       $result = TRUE;
@@ -218,26 +194,6 @@ class Notifications implements EndpointInterface
     return $result;
   }
 
-  /**
-   * @param $array
-   * @return array
-   * Note : simply return all values of a multi-dimensional array.
-   */
-  public 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, $this->getArrayValuesRecursive($value));
-      } else {
-        // If value is not an array, add it to the result
-        $values[] = $value;
-      }
-    }
-    return $values;
-  }
-
   /**
    * @param string $mainTaskDn
    * @return array
diff --git a/plugins/tasks/Reminder.php b/plugins/tasks/Reminder.php
index ca46b55..8cda3fc 100644
--- a/plugins/tasks/Reminder.php
+++ b/plugins/tasks/Reminder.php
@@ -109,13 +109,13 @@ class Reminder implements EndpointInterface
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['uid'] = $task['fdtasksgranulardn'][0];
 
             // Create timeStamp expiration for token
-            $tokenExpire = $this->getTokenExpiration($task['fdtasksgranularhelper'][0],
+            $tokenExpire = TokenUtils::getTokenExpiration($task['fdtasksgranularhelper'][0],
               $remindersMainTask[0]['fdtasksreminderfirstcall'][0],
               $remindersMainTask[0]['fdtasksremindersecondcall'][0]);
             // Create token for SubTask
-            $token = $this->generateToken($task['fdtasksgranulardn'][0], $tokenExpire);
+            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire);
             // Edit the mailForm with the url link containing the token
-            $tokenMailTemplateForm = $this->generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
+            $tokenMailTemplateForm = TokenUtils::generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
             // Recipient email form
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['mail'] = $tokenMailTemplateForm;
 
@@ -136,13 +136,13 @@ class Reminder implements EndpointInterface
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['uid'] = $task['fdtasksgranulardn'][0];
 
             // Create timeStamp expiration for token
-            $tokenExpire = $this->getTokenExpiration($task['fdtasksgranularhelper'][0],
+            $tokenExpire = TokenUtils::getTokenExpiration($task['fdtasksgranularhelper'][0],
               $remindersMainTask[0]['fdtasksreminderfirstcall'][0],
               $remindersMainTask[0]['fdtasksremindersecondcall'][0]);
             // Create token for SubTask
-            $token = $this->generateToken($task['fdtasksgranulardn'][0], $tokenExpire);
+            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire);
             // Edit the mailForm with the url link containing the token
-            $tokenMailTemplateForm = $this->generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
+            $tokenMailTemplateForm = TokenUtils::generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
             // Recipient email form
             $reminders[$remindersMainTaskName]['subTask'][$task['cn'][0]]['mail'] = $tokenMailTemplateForm;
 
@@ -217,207 +217,6 @@ class Reminder implements EndpointInterface
     return $result;
   }
 
-  /**
-   * @param string $token
-   * @param array $mailTemplateForm
-   * @param string $taskDN
-   * @return array
-   */
-  private function generateTokenUrl (string $token, array $mailTemplateForm, string $taskDN): array
-  {
-    //Only take the cn of the main task name :
-    preg_match('/cn=([^,]+),ou=/', $taskDN, $matches);
-    $taskName = $matches[1];
-
-    // Remove the API URI
-    $cleanedUrl = preg_replace('#/rest\.php/v1$#', '', $_ENV['FUSION_DIRECTORY_API_URL']);
-    $url        = $cleanedUrl . '/accountProlongation.php?token=' . $token . '&task=' . $taskName;
-
-    $mailTemplateForm['body'] .= $url;
-
-    return $mailTemplateForm;
-  }
-
-  /**
-   * @param int $subTaskCall
-   * @param int $firstCall
-   * @param int $secondCall
-   * @return int
-   * Note : Simply return the difference between first and second call. (First call can be null).
-   */
-  private function getTokenExpiration (int $subTaskCall, int $firstCall, int $secondCall): int
-  {
-    // if firstCall is empty, secondCall is the timestamp expiry for the token.
-    $result = $secondCall;
-
-    if (!empty($firstCall)) {
-      // Verification if the subTask is the second reminder or the first reminder.
-      if ($subTaskCall === $firstCall) {
-        $result = $firstCall - $secondCall;
-      }
-    }
-
-    return $result;
-  }
-
-  /**
-   * @param string $userDN
-   * @param int $timeStamp
-   * @return string
-   * @throws Exception
-   */
-  private function generateToken (string $userDN, int $timeStamp): string
-  {
-    $token = NULL;
-    // Salt has been generated with APG.
-    $salt    = '8onOlEsItKond';
-    $payload = json_encode($userDN . $salt);
-    // This allows the token to be different every time.
-    $time = time();
-
-    // Create hmac with sha256 alg and the key provided for JWT token signature in ENV.
-    $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 = $this->base64urlEncode($token_hmac);
-
-    // Save token within LDAP
-    $this->saveTokenInLdap($userDN, $token, $timeStamp);
-
-    return $token;
-  }
-
-  /**
-   * @param string $userDN
-   * @param string $token
-   * NOTE : UID is the full DN of the user. (uid=...).
-   * @param int $days
-   * @return bool
-   * @throws Exception
-   */
-  private function saveTokenInLdap (string $userDN, string $token, int $days): bool
-  {
-    $result = FALSE;
-
-    $currentTimestamp = time();
-    // Calculate the future timestamp by adding days to the current timestamp (We actually adds number of seconds).
-    $futureTimestamp = $currentTimestamp + ($days * 24 * 60 * 60);
-
-    preg_match('/uid=([^,]+),ou=/', $userDN, $matches);
-    $uid = $matches[1];
-    $dn  = 'cn=' . $uid . ',' . 'ou=tokens' . ',' . $_ENV["LDAP_BASE"];
-
-    $ldap_entry["objectClass"]      = ['top', 'fdTokenEntry'];
-    $ldap_entry["fdTokenUserDN"]    = $userDN;
-    $ldap_entry["fdTokenType"]      = 'reminder';
-    $ldap_entry["fdToken"]          = $token;
-    $ldap_entry["fdTokenTimestamp"] = $futureTimestamp;
-    $ldap_entry["cn"]               = $uid;
-
-    // set the dn for the token, only take what's between "uid=" and ",ou="
-
-
-    // Verify if token ou branch exists
-    if (!$this->tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"])) {
-      // Create the branch
-      $this->createBranchToken();
-    }
-
-    // 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 ($this->tokenBranchExist($userTokenDN)) {
-      // Remove the user token
-      $this->removeUserToken($userTokenDN);
-    }
-
-    // Add token to LDAP for specific UID
-    try {
-      $result = ldap_add($this->gateway->ds, $dn, $ldap_entry); // bool returned
-    } catch (Exception $e) {
-      echo json_encode(["Ldap Error - Token could not be saved!" => "$e"]); // string returned
-      exit;
-    }
-
-    return $result;
-  }
-
-  /**
-   * @param $userTokenDN
-   * @return void
-   * Note : Simply remove the token for specific user DN
-   */
-  private function removeUserToken ($userTokenDN): void
-  {
-    // Add token to LDAP for specific UID
-    try {
-      $result = ldap_delete($this->gateway->ds, $userTokenDN); // bool returned
-    } catch (Exception $e) {
-      echo json_encode(["Ldap Error - User token could not be removed!" => "$e"]); // string returned
-      exit;
-    }
-  }
-
-  /**
-   * Create ou=pluginManager LDAP branch
-   * @throws Exception
-   */
-  protected function createBranchToken (): void
-  {
-    try {
-      ldap_add(
-        $this->gateway->ds, 'ou=tokens' . ',' . $_ENV["LDAP_BASE"],
-        [
-          'ou'          => 'tokens',
-          'objectClass' => 'organizationalUnit',
-        ]
-      );
-    } catch (Exception $e) {
-
-      echo json_encode(["Ldap Error - Impossible to create the token branch" => "$e"]); // string returned
-      exit;
-    }
-  }
-
-
-  /**
-   * @param string $dn
-   * @return bool
-   * Note : Simply inspect if the branch for token is existing.
-   */
-  private function tokenBranchExist (string $dn): bool
-  {
-    $result = FALSE;
-
-    try {
-      $search = ldap_search($this->gateway->ds, $dn, "(objectClass=*)");
-      // Check if the search was successful
-      if ($search) {
-        // Get the number of entries found
-        $entries = ldap_get_entries($this->gateway->ds, $search);
-
-        // If entries are found, set result to true
-        if ($entries["count"] > 0) {
-          $result = TRUE;
-        }
-      }
-    } catch (Exception $e) {
-      $result = FALSE;
-    }
-
-    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 $dn
    * @return string
@@ -592,26 +391,6 @@ class Reminder implements EndpointInterface
     return DateTime::createFromFormat('Ymd', $dateString);
   }
 
-  /**
-   * @param $array
-   * @return array
-   * Note : simply return all values of a multi-dimensional array.
-   */
-  public 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, $this->getArrayValuesRecursive($value));
-      } else {
-        // If value is not an array, add it to the result
-        $values[] = $value;
-      }
-    }
-    return $values;
-  }
-
   /**
    * @param string $mainTaskDn
    * @return array
-- 
GitLab


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

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

diff --git a/library/Utils.php b/library/Utils.php
index c241a0a..1d24e06 100644
--- a/library/Utils.php
+++ b/library/Utils.php
@@ -2,82 +2,82 @@
 
 class Utils
 {
-    private function __construct() {}
+  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
-    {
-        // 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);
-            }
-        });
+  /**
+   * @param array $array
+   * @return array
+   * Note : Recursively filters out empty values and arrays at any depth.
+   */
+  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 = $this->recursiveArrayFilter($item);
+        // Only retain non-empty arrays
+        return !empty($item);
+      } else {
+        // Retain non-empty scalar values
+        return !empty($item);
+      }
+    });
 
-        return $filtered;
-    }
+    return $filtered;
+  }
 
-    /**
-     * 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 = [];
+  /**
+   * 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 = [];
 
-        if (!empty($elements)) {
-            foreach ($elements as $element) {
-                foreach ($keys as $key) {
-                    if (!empty($element) && array_key_exists($key, $element)) {
-                        $matching[] = $key;
-                    }
-                }
-            }
+    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 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;
-    }
+    return $matching;
+  }
 
-    /**
-     * @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));
+  /**
+   * @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
-- 
GitLab


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

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

diff --git a/library/Utils.php b/library/Utils.php
index 1d24e06..d1afd6d 100644
--- a/library/Utils.php
+++ b/library/Utils.php
@@ -2,7 +2,9 @@
 
 class Utils
 {
-  private function __construct () {}
+  private function __construct ()
+  {
+  }
 
   /**
    * @param array $array
-- 
GitLab


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

---
 library/TokenUtils.php | 361 +++++++++++++++++++++--------------------
 1 file changed, 181 insertions(+), 180 deletions(-)

diff --git a/library/TokenUtils.php b/library/TokenUtils.php
index d19392c..dbf72bb 100644
--- a/library/TokenUtils.php
+++ b/library/TokenUtils.php
@@ -2,196 +2,197 @@
 
 class TokenUtils
 {
-    private function __construct() {
+  private function __construct ()
+  {
+  }
+
+  /**
+   * @param string $userDN
+   * @param int $timeStamp
+   * @return string
+   * @throws Exception
+   */
+  public static function generateToken (string $userDN, int $timeStamp): string
+  {
+    $token = NULL;
+    // Salt has been generated with APG.
+    $salt  = '8onOlEsItKond';
+    $payload = json_encode($userDN . $salt);
+    // This allows the token to be different every time.
+    $time = time();
+
+    // Create hmac with sha256 alg and the key provided for JWT token signature in ENV.
+    $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);
+
+    // Save token within LDAP
+    self::saveTokenInLdap($userDN, $token, $timeStamp);
+
+    return $token;
+  }
+
+  /**
+   * @param string $userDN
+   * @param string $token
+   * NOTE : UID is the full DN of the user. (uid=...).
+   * @param int $days
+   * @return bool
+   * @throws Exception
+   */
+  public static function saveTokenInLdap (string $userDN, string $token, int $days, TaskGateway $gateway): bool
+  {
+    $result = FALSE;
+
+    $currentTimestamp = time();
+    // Calculate the future timestamp by adding days to the current timestamp (We actually adds number of seconds).
+    $futureTimestamp = $currentTimestamp + ($days * 24 * 60 * 60);
+
+    preg_match('/uid=([^,]+),ou=/', $userDN, $matches);
+    $uid = $matches[1];
+    $dn  = 'cn=' . $uid . ',' . 'ou=tokens' . ',' . $_ENV["LDAP_BASE"];
+
+    $ldap_entry["objectClass"]    = ['top', 'fdTokenEntry'];
+    $ldap_entry["fdTokenUserDN"]  = $userDN;
+    $ldap_entry["fdTokenType"]    = 'reminder';
+    $ldap_entry["fdToken"]      = $token;
+    $ldap_entry["fdTokenTimestamp"] = $futureTimestamp;
+    $ldap_entry["cn"]         = $uid;
+
+    // set the dn for the token, only take what's between "uid=" and ",ou="
+
+
+    // Verify if token ou branch exists
+    if (!self::tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"])) {
+      // Create the branch
+      self::createBranchToken();
     }
 
-    /**
-     * @param string $userDN
-     * @param int $timeStamp
-     * @return string
-     * @throws Exception
-     */
-    public static function generateToken (string $userDN, int $timeStamp): string
-    {
-        $token = NULL;
-        // Salt has been generated with APG.
-        $salt    = '8onOlEsItKond';
-        $payload = json_encode($userDN . $salt);
-        // This allows the token to be different every time.
-        $time = time();
-
-        // Create hmac with sha256 alg and the key provided for JWT token signature in ENV.
-        $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);
-
-        // Save token within LDAP
-        self::saveTokenInLdap($userDN, $token, $timeStamp);
-
-        return $token;
+    // 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)) {
+      // Remove the user token
+      self::removeUserToken($userTokenDN);
     }
 
-    /**
-     * @param string $userDN
-     * @param string $token
-     * NOTE : UID is the full DN of the user. (uid=...).
-     * @param int $days
-     * @return bool
-     * @throws Exception
-     */
-    public static function saveTokenInLdap (string $userDN, string $token, int $days, TaskGateway $gateway): bool
-    {
-        $result = FALSE;
-
-        $currentTimestamp = time();
-        // Calculate the future timestamp by adding days to the current timestamp (We actually adds number of seconds).
-        $futureTimestamp = $currentTimestamp + ($days * 24 * 60 * 60);
-
-        preg_match('/uid=([^,]+),ou=/', $userDN, $matches);
-        $uid = $matches[1];
-        $dn  = 'cn=' . $uid . ',' . 'ou=tokens' . ',' . $_ENV["LDAP_BASE"];
-
-        $ldap_entry["objectClass"]      = ['top', 'fdTokenEntry'];
-        $ldap_entry["fdTokenUserDN"]    = $userDN;
-        $ldap_entry["fdTokenType"]      = 'reminder';
-        $ldap_entry["fdToken"]          = $token;
-        $ldap_entry["fdTokenTimestamp"] = $futureTimestamp;
-        $ldap_entry["cn"]               = $uid;
-
-        // set the dn for the token, only take what's between "uid=" and ",ou="
-
-
-        // Verify if token ou branch exists
-        if (!self::tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"])) {
-            // Create the branch
-            self::createBranchToken();
-        }
-
-        // 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)) {
-            // Remove the user token
-            self::removeUserToken($userTokenDN);
-        }
-
-        // Add token to LDAP for specific UID
-        try {
-            $result = ldap_add($gateway->ds, $dn, $ldap_entry); // bool returned
-        } catch (Exception $e) {
-            echo json_encode(["Ldap Error - Token could not be saved!" => "$e"]); // string returned
-            exit;
-        }
-
-        return $result;
-    }
-
-    /**
-     * @param int $subTaskCall
-     * @param int $firstCall
-     * @param int $secondCall
-     * @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
-    {
-        // if firstCall is empty, secondCall is the timestamp expiry for the token.
-        $result = $secondCall;
-
-        if (!empty($firstCall)) {
-            // Verification if the subTask is the second reminder or the first reminder.
-            if ($subTaskCall === $firstCall) {
-                $result = $firstCall - $secondCall;
-            }
-        }
-
-        return $result;
+    // Add token to LDAP for specific UID
+    try {
+      $result = ldap_add($gateway->ds, $dn, $ldap_entry); // bool returned
+    } catch (Exception $e) {
+      echo json_encode(["Ldap Error - Token could not be saved!" => "$e"]); // string returned
+      exit;
     }
 
-    /**
-     * @param $userTokenDN
-     * @return void
-     * Note : Simply remove the token for specific user DN
-     */
-    public static function removeUserToken ($userTokenDN, TaskGateway $gateway): void
-    {
-        // Add token to LDAP for specific UID
-        try {
-            $result = ldap_delete($gateway->ds, $userTokenDN); // bool returned
-        } catch (Exception $e) {
-            echo json_encode(["Ldap Error - User token could not be removed!" => "$e"]); // string returned
-            exit;
-        }
+    return $result;
+  }
+
+  /**
+   * @param int $subTaskCall
+   * @param int $firstCall
+   * @param int $secondCall
+   * @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
+  {
+    // if firstCall is empty, secondCall is the timestamp expiry for the token.
+    $result = $secondCall;
+
+    if (!empty($firstCall)) {
+      // Verification if the subTask is the second reminder or the first reminder.
+      if ($subTaskCall === $firstCall) {
+        $result = $firstCall - $secondCall;
+      }
     }
 
-    /**
-     * Create ou=pluginManager LDAP branch
-     * @throws Exception
-     */
-    public static function createBranchToken (TaskGateway $gateway): void
-    {
-        try {
-            ldap_add(
-                $gateway->ds, 'ou=tokens' . ',' . $_ENV["LDAP_BASE"],
-                [
-                    'ou'          => 'tokens',
-                    'objectClass' => 'organizationalUnit',
-                ]
-            );
-        } catch (Exception $e) {
-
-            echo json_encode(["Ldap Error - Impossible to create the token branch" => "$e"]); // string returned
-            exit;
-        }
+    return $result;
+  }
+
+  /**
+   * @param $userTokenDN
+   * @return void
+   * Note : Simply remove the token for specific user DN
+   */
+  public static function removeUserToken ($userTokenDN, TaskGateway $gateway): void
+  {
+    // Add token to LDAP for specific UID
+    try {
+      $result = ldap_delete($gateway->ds, $userTokenDN); // bool returned
+    } catch (Exception $e) {
+      echo json_encode(["Ldap Error - User token could not be removed!" => "$e"]); // string returned
+      exit;
     }
-
-    /**
-     * @param string $token
-     * @param array $mailTemplateForm
-     * @param string $taskDN
-     * @return array
-     */
-    public static function generateTokenUrl (string $token, array $mailTemplateForm, string $taskDN): array
-    {
-        //Only take the cn of the main task name :
-        preg_match('/cn=([^,]+),ou=/', $taskDN, $matches);
-        $taskName = $matches[1];
-
-        // Remove the API URI
-        $cleanedUrl = preg_replace('#/rest\.php/v1$#', '', $_ENV['FUSION_DIRECTORY_API_URL']);
-        $url        = $cleanedUrl . '/accountProlongation.php?token=' . $token . '&task=' . $taskName;
-
-        $mailTemplateForm['body'] .= $url;
-
-        return $mailTemplateForm;
+  }
+
+  /**
+   * Create ou=pluginManager LDAP branch
+   * @throws Exception
+   */
+  public static function createBranchToken (TaskGateway $gateway): void
+  {
+    try {
+      ldap_add(
+        $gateway->ds, 'ou=tokens' . ',' . $_ENV["LDAP_BASE"],
+        [
+          'ou'      => 'tokens',
+          'objectClass' => 'organizationalUnit',
+        ]
+      );
+    } catch (Exception $e) {
+
+      echo json_encode(["Ldap Error - Impossible to create the token branch" => "$e"]); // string returned
+      exit;
     }
-
-    /**
-     * @param string $dn
-     * @return bool
-     * Note : Simply inspect if the branch for token is existing.
-     */
-    public static function tokenBranchExist (string $dn, TaskGateway $gateway): bool
-    {
-        $result = FALSE;
-
-        try {
-            $search = ldap_search($gateway->ds, $dn, "(objectClass=*)");
-            // Check if the search was successful
-            if ($search) {
-                // Get the number of entries found
-                $entries = ldap_get_entries($gateway->ds, $search);
-
-                // If entries are found, set result to true
-                if ($entries["count"] > 0) {
-                    $result = TRUE;
-                }
-            }
-        } catch (Exception $e) {
-            $result = FALSE;
+  }
+
+  /**
+   * @param string $token
+   * @param array $mailTemplateForm
+   * @param string $taskDN
+   * @return array
+   */
+  public static function generateTokenUrl (string $token, array $mailTemplateForm, string $taskDN): array
+  {
+    //Only take the cn of the main task name :
+    preg_match('/cn=([^,]+),ou=/', $taskDN, $matches);
+    $taskName = $matches[1];
+
+    // Remove the API URI
+    $cleanedUrl = preg_replace('#/rest\.php/v1$#', '', $_ENV['FUSION_DIRECTORY_API_URL']);
+    $url    = $cleanedUrl . '/accountProlongation.php?token=' . $token . '&task=' . $taskName;
+
+    $mailTemplateForm['body'] .= $url;
+
+    return $mailTemplateForm;
+  }
+
+  /**
+   * @param string $dn
+   * @return bool
+   * Note : Simply inspect if the branch for token is existing.
+   */
+  public static function tokenBranchExist (string $dn, TaskGateway $gateway): bool
+  {
+    $result = FALSE;
+
+    try {
+      $search = ldap_search($gateway->ds, $dn, "(objectClass=*)");
+      // Check if the search was successful
+      if ($search) {
+        // Get the number of entries found
+        $entries = ldap_get_entries($gateway->ds, $search);
+
+        // If entries are found, set result to true
+        if ($entries["count"] > 0) {
+          $result = TRUE;
         }
-
-        return $result;
+      }
+    } catch (Exception $e) {
+      $result = FALSE;
     }
+
+    return $result;
+  }
 }
\ No newline at end of file
-- 
GitLab


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

---
 library/TokenUtils.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/library/TokenUtils.php b/library/TokenUtils.php
index dbf72bb..7a6ebd9 100644
--- a/library/TokenUtils.php
+++ b/library/TokenUtils.php
@@ -136,7 +136,7 @@ class TokenUtils
       ldap_add(
         $gateway->ds, 'ou=tokens' . ',' . $_ENV["LDAP_BASE"],
         [
-          'ou'      => 'tokens',
+          'ou'          => 'tokens',
           'objectClass' => 'organizationalUnit',
         ]
       );
-- 
GitLab


From b39f4e4cc54ea297b9aa42dceb6f24b9511acb68 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:14:46 +0100
Subject: [PATCH 06/22] fix params

---
 library/TokenUtils.php     | 12 ++++++------
 plugins/tasks/Reminder.php |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/library/TokenUtils.php b/library/TokenUtils.php
index 7a6ebd9..8552514 100644
--- a/library/TokenUtils.php
+++ b/library/TokenUtils.php
@@ -12,7 +12,7 @@ class TokenUtils
    * @return string
    * @throws Exception
    */
-  public static function generateToken (string $userDN, int $timeStamp): string
+  public static function generateToken (string $userDN, int $timeStamp, TaskGateway $gateway): string
   {
     $token = NULL;
     // Salt has been generated with APG.
@@ -28,7 +28,7 @@ class TokenUtils
     $token = Utils::base64urlEncode($token_hmac);
 
     // Save token within LDAP
-    self::saveTokenInLdap($userDN, $token, $timeStamp);
+    self::saveTokenInLdap($userDN, $token, $timeStamp, $gateway);
 
     return $token;
   }
@@ -64,17 +64,17 @@ class TokenUtils
 
 
     // Verify if token ou branch exists
-    if (!self::tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"])) {
+    if (!self::tokenBranchExist('ou=tokens' . ',' . $_ENV["LDAP_BASE"], $gateway)) {
       // Create the branch
-      self::createBranchToken();
+      self::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)) {
+    if (self::tokenBranchExist($userTokenDN, $gateway)) {
       // Remove the user token
-      self::removeUserToken($userTokenDN);
+      self::removeUserToken($userTokenDN, $gateway);
     }
 
     // Add token to LDAP for specific UID
diff --git a/plugins/tasks/Reminder.php b/plugins/tasks/Reminder.php
index 8cda3fc..1faeff7 100644
--- a/plugins/tasks/Reminder.php
+++ b/plugins/tasks/Reminder.php
@@ -113,7 +113,7 @@ class Reminder implements EndpointInterface
               $remindersMainTask[0]['fdtasksreminderfirstcall'][0],
               $remindersMainTask[0]['fdtasksremindersecondcall'][0]);
             // Create token for SubTask
-            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire);
+            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire, $this->gateway);
             // Edit the mailForm with the url link containing the token
             $tokenMailTemplateForm = TokenUtils::generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
             // Recipient email form
@@ -140,7 +140,7 @@ class Reminder implements EndpointInterface
               $remindersMainTask[0]['fdtasksreminderfirstcall'][0],
               $remindersMainTask[0]['fdtasksremindersecondcall'][0]);
             // Create token for SubTask
-            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire);
+            $token = TokenUtils::generateToken($task['fdtasksgranulardn'][0], $tokenExpire, $this->gateway);
             // Edit the mailForm with the url link containing the token
             $tokenMailTemplateForm = TokenUtils::generateTokenUrl($token, $mailTemplateForm, $remindersMainTaskName);
             // Recipient email form
-- 
GitLab


From fc915a520d4ef4630ca98163789780467a8cb687 Mon Sep 17 00:00:00 2001
From: Oana-Eliza Alexa <43857161+alexaeliza@users.noreply.github.com>
Date: Mon, 24 Mar 2025 12:15:32 +0100
Subject: [PATCH 07/22] fix self

---
 library/Utils.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/library/Utils.php b/library/Utils.php
index d1afd6d..1c132ac 100644
--- a/library/Utils.php
+++ b/library/Utils.php
@@ -17,7 +17,7 @@ class Utils
     $filtered = array_filter($array, function ($item) {
       if (is_array($item)) {
         // Recursively filter the sub-array
-        $item = $this->recursiveArrayFilter($item);
+        $item = self::recursiveArrayFilter($item);
         // Only retain non-empty arrays
         return !empty($item);
       } else {
-- 
GitLab


From 9a0adfbb4696bbb0e8d8fddd1e9826b3e35c5ef0 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 08/22] 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 3198ae3d1501c7ef7ce05b873aa4f971f06c7ed3 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 09/22] 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 817f80ada8347214ae53b400d8a32d8d74b3f253 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/22] 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 752fcad55a62061ad1cbdb22b0fb1e0199f24b70 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/22] 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 c8555f5bed86667a7bd0f75d3014063d9ce965eb 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/22] 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 b0604bd5deeea3d8002ff629346c119a2213b69c 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/22] 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 ad060812c079c616144192bc483add434a416f79 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/22] 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 bd1ea57e3bcac3a5e6ba4a94da88737d3ab6c70e 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/22] 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 4b08c0eae0b003610e116f759d940ddac51058a6 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 16/22] :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 98a44f282f695208f34e92e994ddf2732ee33a18 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 17/22] :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 b64f5b3e33f1793a70f1c406d987d0e2ea588a5d 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 18/22] :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 2120e7d5fb8bed220edae73dc8cdbda59a1423b2 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 19/22] :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 a381122877a5281a8396afbfd7a318dda6ba4e9a 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 20/22] :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 9edc95cfa56270005a6c438a2dbf332922226dc0 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 21/22] :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 98320b15ea79ee0c9522c80124e0c62a366d01fc 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 22/22] :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