From b739683d96335fcd2e6efde8f24b42325c94b046 Mon Sep 17 00:00:00 2001
From: Antonin <antonin.murtin@gmail.com>
Date: Wed, 4 May 2016 01:27:51 +0200
Subject: [PATCH] Install : check that the config.php file is written.

---
 app/classes/Framadate/Services/InstallService.php | 14 ++++++++------
 app/inc/init.php                                  |  4 ++--
 locale/de.json                                    |  3 ++-
 locale/en.json                                    |  3 ++-
 locale/es.json                                    |  3 ++-
 locale/fr.json                                    |  3 ++-
 locale/it.json                                    |  3 ++-
 locale/oc.json                                    |  3 ++-
 8 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/app/classes/Framadate/Services/InstallService.php b/app/classes/Framadate/Services/InstallService.php
index 0db9f1f8..65527ade 100644
--- a/app/classes/Framadate/Services/InstallService.php
+++ b/app/classes/Framadate/Services/InstallService.php
@@ -4,16 +4,16 @@
  * is not distributed with this file, you can obtain one at
  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
  *
- * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
+ * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Rapha�l DROZ
  * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
  *
  * =============================
  *
- * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
+ * Ce logiciel est r�gi par la licence CeCILL-B. Si une copie de cette licence
  * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
  *
- * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
+ * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Rapha�l DROZ
  * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
  */
 namespace Framadate\Services;
@@ -62,7 +62,9 @@ class InstallService {
         }
 
         // Write configuration to conf.php file
-        $this->writeConfiguration($smarty);
+        if ($this->writeConfiguration($smarty) === false) {
+            return $this->error(__f('Error', "Can't create the config.php file in '%s'.", CONF_FILENAME));
+        }
 
         return $this->ok();
     }
@@ -85,14 +87,14 @@ class InstallService {
 
         $content = $smarty->fetch('admin/config.tpl');
 
-        $this->writeToFile($content);
+        return $this->writeToFile($content);
     }
 
     /**
      * @param $content
      */
     function writeToFile($content) {
-        file_put_contents(CONF_FILENAME, $content);
+        return @file_put_contents(CONF_FILENAME, $content);
     }
 
     /**
diff --git a/app/inc/init.php b/app/inc/init.php
index 8879bae7..35a6ac1b 100644
--- a/app/inc/init.php
+++ b/app/inc/init.php
@@ -34,9 +34,9 @@ if (ini_get('date.timezone') == '') {
 define('ROOT_DIR', __DIR__ . '/../../');
 define('CONF_FILENAME', ROOT_DIR . '/app/inc/config.php');
 
-if (is_file(CONF_FILENAME)) {
+require_once __DIR__ . '/constants.php';
 
-    require_once __DIR__ . '/constants.php';
+if (is_file(CONF_FILENAME)) {
     @include_once __DIR__ . '/config.php';
 
     // Connection to database
diff --git a/locale/de.json b/locale/de.json
index 6d7ce505..f80fd65c 100644
--- a/locale/de.json
+++ b/locale/de.json
@@ -383,7 +383,8 @@
         "Password is empty": "DE_Le mot de passe est vide.",
         "Passwords do not match": "DE_Les mot de passes ne correspondent pas.",
         "Poll id already used": "DE_L'identifiant est déjà utilisé",
-        "You can't select more than %d dates": "DE_Vous ne pouvez pas choisir plus de %d dates"
+        "You can't select more than %d dates": "DE_Vous ne pouvez pas choisir plus de %d dates",
+        "Can't create the config.php file in '%s'.": "DE_Impossible de créer le fichier config.php dans '%s'."
     },
     "Check": {
         "Installation checking": "DE_Vérifications de l'installation",
diff --git a/locale/en.json b/locale/en.json
index 2921bdc2..25236499 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -384,7 +384,8 @@
     "Password is empty": "Password is empty.",
     "Passwords do not match": "Passwords do not match.",
     "Poll id already used": "Identifier is already used",
-    "You can't select more than %d dates": "You can't select more than %d dates"
+    "You can't select more than %d dates": "You can't select more than %d dates",
+    "Can't create the config.php file in '%s'.": "Can't create the config.php file in '%s'."
   },
   "Check": {
     "Installation checking": "Installation checking",
diff --git a/locale/es.json b/locale/es.json
index 5eec32a9..7d777c3d 100644
--- a/locale/es.json
+++ b/locale/es.json
@@ -383,7 +383,8 @@
     "Password is empty": "ES_Le mot de passe est vide.",
     "Passwords do not match": "ES_Les mot de passes ne correspondent pas.",
     "Poll id already used": "ES_L'identifiant est déjà utilisé",
-    "You can't select more than %d dates": "ES_Vous ne pouvez pas choisir plus de %d dates"
+    "You can't select more than %d dates": "ES_Vous ne pouvez pas choisir plus de %d dates",
+    "Can't create the config.php file in '%s'.": "ES_Impossible de créer le fichier config.php dans '%s'."
   },
   "Check": {
     "Installation checking": "ES_Vérifications de l'installation",
diff --git a/locale/fr.json b/locale/fr.json
index 7ce19f95..1802c242 100644
--- a/locale/fr.json
+++ b/locale/fr.json
@@ -397,7 +397,8 @@
     "Password is empty": "Le mot de passe est vide.",
     "Passwords do not match": "Les mots de passe ne correspondent pas.",
     "Poll id already used": "L'identifiant est déjà utilisé",
-    "You can't select more than %d dates": "Vous ne pouvez pas choisir plus de %d dates"
+    "You can't select more than %d dates": "Vous ne pouvez pas choisir plus de %d dates",
+    "Can't create the config.php file in '%s'.": "Impossible de créer le fichier config.php dans '%s'."
   },
   "Check": {
     "Installation checking": "Vérifications de l'installation",
diff --git a/locale/it.json b/locale/it.json
index 5595587d..e55392b1 100644
--- a/locale/it.json
+++ b/locale/it.json
@@ -381,7 +381,8 @@
     "MISSING_VALUES": "Valori mancanti",
     "CANT_CONNECT_TO_DATABASE": "Impossibile connettersi al database",
     "Poll id already used": "IT_L'identifiant est déjà utilisé",
-    "You can't select more than %d dates": "IT_Vous ne pouvez pas choisir plus de %d dates"
+    "You can't select more than %d dates": "IT_Vous ne pouvez pas choisir plus de %d dates",
+    "Can't create the config.php file in '%s'.": "IT_Impossible de créer le fichier config.php dans '%s'."
   },
   "Check": {
     "Installation checking": "IT_Vérifications de l'installation",
diff --git a/locale/oc.json b/locale/oc.json
index e885df1d..fea5973c 100644
--- a/locale/oc.json
+++ b/locale/oc.json
@@ -379,7 +379,8 @@
     "The column already exists": "La colomna existís ja",
     "MISSING_VALUES": "Mancan de valors",
     "CANT_CONNECT_TO_DATABASE": "Impossible de se connectar a la banca de donadas",
-    "You can't select more than %d dates": "OC_Vous ne pouvez pas choisir plus de %d dates"
+    "You can't select more than %d dates": "OC_Vous ne pouvez pas choisir plus de %d dates",
+    "Can't create the config.php file in '%s'.": "OC_Impossible de créer le fichier config.php dans '%s'."
   },
   "Check": {
     "Installation checking": "OC_Vérifications de l'installation",
-- 
GitLab