From d5d91c8eb90d062f9dae36dba05725fa93cd2a43 Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Tue, 18 Mar 2025 12:55:04 +0000
Subject: [PATCH] :sparkles: Feat(installation) - Installation part 1

Adapts setup to php8.2 - installation part 1
---
 html/setup.php                                |  4 ++-
 include/class_config.inc                      | 22 +++++++-----
 .../columns/class_supannEtatDateColumn.inc    |  2 +-
 include/simpleplugin/class_simplePlugin.inc   |  1 -
 setup/class_setupStep.inc                     | 34 ++++++++++---------
 setup/class_setupStepWelcome.inc              |  1 -
 6 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/html/setup.php b/html/setup.php
index a39929fec..2ef305939 100755
--- a/html/setup.php
+++ b/html/setup.php
@@ -56,8 +56,10 @@ session_cache_expire(60 * 24);
 ini_set("session.gc_maxlifetime", 24 * 60 * 60);
 
 /* Start session */
-session::start();
+session_start(); // Start or resume the session
+
 session::set('DEBUGLEVEL', 0);
+session::set('SETUP_INIT', TRUE);
 
 CSRFProtection::check();
 
diff --git a/include/class_config.inc b/include/class_config.inc
index e569a72a8..9f9028a03 100755
--- a/include/class_config.inc
+++ b/include/class_config.inc
@@ -105,25 +105,28 @@ class config
    * @return void
    * Note : Magic method allowing to regenerate required data set in $_SESSION during restoration.
    */
-  public function __unserialize(array $data): void
+  public function __unserialize (array $data): void
   {
-    $this->config_found = $data['config_found'];
-    $this->tags = $data['tags'];
-    $this->level = $data['level'];
+    $this->config_found    = $data['config_found'];
+    $this->tags            = $data['tags'];
+    $this->level           = $data['level'];
     $this->currentLocation = $data['currentLocation'];
-    $this->current = $data['current'];
-    $this->referrals = $data['referrals'];
-    $this->data = $data['data'];
+    $this->current         = $data['current'];
+    $this->referrals       = $data['referrals'];
+    $this->data            = $data['data'];
 
     // We reset the value of hooks (avoiding duplication).
     $this->data['HOOKS'] = [];
 
     // Recreate the XML parser
     $this->parser = xml_parser_create();
-    // Update config from backend
-    $this->load_inldap_config();
+    // Update config from backend only if not currently performing FD installation.
+    if ($_SESSION['SETUP_INIT'] === FALSE) {
+      $this->load_inldap_config();
+    }
   }
 
+
   /*!
    * \brief Check and reload the configuration
    *
@@ -351,6 +354,7 @@ class config
 
     if (($this->ldapLink === NULL) || ($this->ldapLink->cid === FALSE)) {
       /* Build new connection */
+
       $this->ldapLink = LDAP::init($this->current['SERVER'], $this->current['BASE'],
           $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
 
diff --git a/include/management/columns/class_supannEtatDateColumn.inc b/include/management/columns/class_supannEtatDateColumn.inc
index 538d3d0aa..c2dfe073b 100644
--- a/include/management/columns/class_supannEtatDateColumn.inc
+++ b/include/management/columns/class_supannEtatDateColumn.inc
@@ -63,7 +63,7 @@ class SupannEtatDateColumn extends LinkColumn
 
       try {
         return (new DateTimeImmutable())->setDate($year, $month, $day);
-      } catch (\Exception $e) {
+      } catch (\Exception) {
       }
     }
     return NULL;
diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc
index 96e360307..153be210b 100755
--- a/include/simpleplugin/class_simplePlugin.inc
+++ b/include/simpleplugin/class_simplePlugin.inc
@@ -307,7 +307,6 @@ class simplePlugin implements SimpleTab
     }
   }
 
-
   public static function setUserLocked (bool $locked): void
   {
     self::$user_locked = $locked;
diff --git a/setup/class_setupStep.inc b/setup/class_setupStep.inc
index 6c9222bbe..ac0d6a34c 100755
--- a/setup/class_setupStep.inc
+++ b/setup/class_setupStep.inc
@@ -44,26 +44,28 @@ class setupStep extends simplePlugin
 
   public function __serialize(): array
   {
-    return [
-      's_short_name'   => $this->s_short_name,
-      's_title'        => $this->s_title,
-      's_description'  => $this->s_description,
-      'is_active'      => $this->is_active,
-      'is_enabled'     => $this->is_enabled,
-      'is_completed'   => $this->is_completed,
-      'header_image'   => $this->header_image,
-    ];
+    $data = [];
+
+    foreach (get_object_vars($this) as $key => $value) {
+      if (is_resource($value)) {
+        continue;
+      }
+
+      if ($value instanceof \LDAP\Connection) {
+        continue;
+      }
+
+      $data[$key] = $value;
+    }
+
+    return $data;
   }
 
   public function __unserialize(array $data): void
   {
-    $this->s_short_name   = $data['s_short_name'] ?? 'Still undefined';
-    $this->s_title        = $data['s_title'] ?? 'Still undefined';
-    $this->s_description  = $data['s_description'] ?? 'Still undefined';
-    $this->is_active      = $data['is_active'] ?? FALSE;
-    $this->is_enabled     = $data['is_enabled'] ?? FALSE;
-    $this->is_completed   = $data['is_completed'] ?? FALSE;
-    $this->header_image   = $data['header_image'] ?? '';
+    foreach ($data as $key => $value) {
+      $this->$key = $value;
+    }
   }
 
   function update_strings ()
diff --git a/setup/class_setupStepWelcome.inc b/setup/class_setupStepWelcome.inc
index 94ddfcba3..1e28e375f 100755
--- a/setup/class_setupStepWelcome.inc
+++ b/setup/class_setupStepWelcome.inc
@@ -38,7 +38,6 @@ class setupStepWelcome extends setupStep
   function __construct ($parent)
   {
     parent::__construct($parent);
-
     $this->is_enabled     = TRUE;
     $this->is_active      = TRUE;
     $this->authPath       = CACHE_DIR.'fusiondirectory.auth';
-- 
GitLab