From c3633a4372c268c1347effd3912b6436c45c995d Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Fri, 19 Jun 2020 17:01:04 +0200
Subject: [PATCH] FEAT #13671 TIME 0:35 Database creation fix + save config

---
 src/core/controllers/InstallerController.php | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/core/controllers/InstallerController.php b/src/core/controllers/InstallerController.php
index 8f75a54713e..2126852dbc8 100644
--- a/src/core/controllers/InstallerController.php
+++ b/src/core/controllers/InstallerController.php
@@ -213,7 +213,7 @@ class InstallerController
         $dsn = "pgsql:host={$body['server']};port={$body['port']};dbname={$body['name']}";
         $db = new \PDO($dsn, $body['user'], $body['password'], $options);
 
-        $fileContent = file_get_contents('sql/structure.sql');
+        $fileContent = @file_get_contents('sql/structure.sql');
         if (!$fileContent) {
             return $response->withStatus(400)->withJson(['errors' => 'Cannot read structure.sql']);
         }
@@ -223,7 +223,7 @@ class InstallerController
         }
 
         if (!empty($body['data'])) {
-            $fileContent = file_get_contents("sql/{$body['data']}.sql");
+            $fileContent = @file_get_contents("sql/{$body['data']}.sql");
             if (!$fileContent) {
                 return $response->withStatus(400)->withJson(['errors' => "Cannot read {$body['data']}.sql"]);
             }
@@ -233,6 +233,22 @@ class InstallerController
             }
         }
 
+        $configFile = CoreConfigModel::getJsonLoaded(['path' => "custom/{$body['customName']}/apps/maarch_entreprise/xml/config.json"]);
+        $configFile['database'] = [
+            [
+                "server"    => $body['server'],
+                "port"      => $body['port'],
+                "type"      => 'POSTGRESQL',
+                "name"      => $body['name'],
+                "user"      => $body['user'],
+                "password"  => $body['password']
+            ]
+        ];
+
+        $fp = fopen("custom/{$body['customName']}/apps/maarch_entreprise/xml/config.json", 'w');
+        fwrite($fp, json_encode($configFile, JSON_PRETTY_PRINT));
+        fclose($fp);
+
         return $response->withStatus(204);
     }
 }
-- 
GitLab