From 0c6553ff094866e494c066d0140adca527b91dc0 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Mon, 24 Jul 2023 13:29:34 +0200
Subject: [PATCH] take error message from language file

---
 config/lang/de-de.json                           | 2 ++
 config/lang/en-en.json                           | 2 ++
 public_html/deployment/classes/project.class.php | 4 ++--
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/config/lang/de-de.json b/config/lang/de-de.json
index 5ac8fc5e..cb4cd76c 100644
--- a/config/lang/de-de.json
+++ b/config/lang/de-de.json
@@ -79,6 +79,8 @@
     "class-project-error-build-docroot-not-found": "Es gibt kein Unterverzeichnis &quot;public_html&quot; oder &quot;public&quot; im Arbeitsverzeichnis.",
     "class-project-error-build-packaging-failed": "Build schlug beim Erstellen der Pakete fehl.",
     "class-project-error-command-failed": "Eines der Kommandos ist fehlgeschlagen (s. Fehlermeldung in der Ausgabe).<br>Frage ggf. den Administrator. Das Arbeitsverzeichnis wird f&uumlr eine Analyse nicht gel&ouml;scht.",
+    "class-project-error-config-invalid": "Fehler in der Konfiguration des Projects [%s]: dies ist keine g&uuml;ltige JSON Datei: %s",
+    "class-project-error-config-wrongid": "Fehler: die Projekt-ID enth&auml;lt ung&uuml;ltige Zeichen: %s",
     "class-project-error-getPhaseInfos-package-not-found": "Die Paket-Datei (.tgz) wurde nicht gefunden: %s",
     "class-project-error-getPhaseInfos-requires-phase": "Die Methode getPhaseInfos erfordert die Angabe eine Phase.",
     "class-project-error-datafile-does-not-exist": "Die Paket-Datei &quot;%s&quot; existiert nicht.",
diff --git a/config/lang/en-en.json b/config/lang/en-en.json
index b30efa89..d7dbdb91 100644
--- a/config/lang/en-en.json
+++ b/config/lang/en-en.json
@@ -78,6 +78,8 @@
     "class-project-error-build-docroot-not-found": "There is no subdirectory &quot;public_html&quot; or &quot;public&quot; in the working directory.",
     "class-project-error-build-packaging-failed": "Build failed while creating the packages.",
     "class-project-error-command-failed": "The execution of a command failed (see error message in the output below).<br>Ask your admin. The working directory was NOT deleted that you can analyze the problem.",
+    "class-project-error-config-invalid": "ERROR in configuration of project [%s]: this is mot valid JSON file: %s",
+    "class-project-error-config-wrongid": "ERROR: invalid syntax in project ID: %s",
     "class-project-error-getPhaseInfos-package-not-found": "The package file (.tgz) was not found: %s",
     "class-project-error-getPhaseInfos-requires-phase": "The method getPhaseInfos requires the name of a pfase.",
     "class-project-error-datafile-does-not-exist": "The package file &quot;%s&quot; does not exist.",
diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index e2a0ccb2..a7806859 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -1484,7 +1484,7 @@ class project extends base {
      */
     public function setProjectById($sId) {
         if ($sId !== preg_replace('/[^a-z0-9\-\_]/i', '', $sId)) {
-            echo "ERROR: invalid syntax in project ID: $sId<br>";
+            $this->_errors[]=sprintf(t("class-project-error-config-wrongid"), htmlentities($sId));
             return false;
         }
         $this->_aPrjConfig = [];
@@ -1498,7 +1498,7 @@ class project extends base {
             }
             $_aPrjConfigTmp=json_decode(file_get_contents($this->_getConfigFile($sId)), true);
             if(!$_aPrjConfigTmp){
-                $this->_errors[]="ERROR in configuration of project [$sId]: this is mot valid JSON file: ".$this->_getConfigFile($sId);
+                $this->_errors[]=sprintf(t("class-project-error-config-invalid"), $sId, $this->_getConfigFile($sId));
                 return false;
             }
             $this->_aPrjConfig = $_aPrjConfigTmp;
-- 
GitLab