From ded52c26050c9fc69daf7b152dcaf8554e983997 Mon Sep 17 00:00:00 2001
From: Jean-Laurent DUZANT <jean-laurent.duzant@xelians.fr>
Date: Tue, 21 Feb 2023 11:06:44 +0100
Subject: [PATCH] FEAT #23832 TIME 0:20 manage database redondant

---
 config/config.default.json      | 18 ++++++++++--------
 src/core/models/DatabasePDO.php |  9 ++-------
 2 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/config/config.default.json b/config/config.default.json
index 04cec1d810..a9d8b09fc4 100644
--- a/config/config.default.json
+++ b/config/config.default.json
@@ -4,14 +4,16 @@
         "timezone": "Europe/Paris",
         "customLangPathDirectory": ""
     },
-    "database": {
-        "server": "localhost",
-        "port": "5432",
-        "type": "POSTGRESQL",
-        "name": "maarch",
-        "user": "maarch",
-        "password": "maarch"
-    },
+    "databases": [
+        {
+            "server": "localhost",
+            "port": "5432",
+            "type": "POSTGRESQL",
+            "name": "maarch",
+            "user": "maarch",
+            "password": "maarch"
+        }
+    ],
     "electronicSignature": {
         "enable": false,
         "certPath": "/var/www/html/MaarchParapheur/samples/certs/MP_final_certificate.crt",
diff --git a/src/core/models/DatabasePDO.php b/src/core/models/DatabasePDO.php
index 97f9320036..e2ca167b93 100755
--- a/src/core/models/DatabasePDO.php
+++ b/src/core/models/DatabasePDO.php
@@ -37,12 +37,8 @@ class DatabasePDO
             throw new \Exception('Configuration file can not be read');
         }
 
-        $databases = array_filter($loaderJson, function($value, $key) {
-            return strpos($key, 'database') !== false;
-        }, ARRAY_FILTER_USE_BOTH);
 
-        $count = 1;
-        foreach ($databases as $key => $database) {
+        foreach ($loaderJson['databases'] as $key => $database) {
             $server     = $database['server'];
             $port       = $database['port'];
             $name       = $database['name'];
@@ -84,8 +80,7 @@ class DatabasePDO
                     self::$pdo = new \PDO($dsn, $user, $password, $options);
                     break;
                 } catch (\PDOException $PDOException) {
-                    if (!empty($loaderJson[$key . $count])) {
-                        $count++;
+                    if (!empty($loaderJson['databases'][$key + 1])) {
                         continue;
                     } else {
                         throw new \Exception($PDOException->getMessage());
-- 
GitLab