From c958ea94840e4824bec5d347b8c0a9397e4139c2 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Mon, 24 Jul 2023 12:37:34 +0200 Subject: [PATCH] add array for init errors and a rendering function --- .../deployment/classes/project.class.php | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index e1a38611..e2a0ccb2 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -113,6 +113,12 @@ class project extends base { */ protected $oMessenger = false; + /** + * collected errors + * @var array + */ + protected $_errors = []; + // ---------------------------------------------------------------------- // constructor // ---------------------------------------------------------------------- @@ -868,7 +874,7 @@ class project extends base { * @return string */ public function getLabel() { - return $this->_aPrjConfig["label"]; + return isset($this->_aPrjConfig["label"]) ? $this->_aPrjConfig["label"] : ''; } /** @@ -876,7 +882,7 @@ class project extends base { * @return string */ public function getDescription() { - return $this->_aPrjConfig["description"]; + return isset($this->_aPrjConfig["description"]) ? $this->_aPrjConfig["description"] : ''; } /** @@ -884,7 +890,7 @@ class project extends base { * @return string */ public function getId(){ - return $this->_aConfig["id"]; + return isset($this->_aConfig["id"]) ? $this->_aConfig["id"] : ''; } /** * get deploy and queue infos for all phases @@ -1481,16 +1487,21 @@ class project extends base { echo "ERROR: invalid syntax in project ID: $sId<br>"; return false; } - $this->_aPrjConfig = array(); + $this->_aPrjConfig = []; $this->_aConfig["id"] = $sId; - + $this->_errors = []; if (isset($this->_aConfig['projects']['json']['active']) && $this->_aConfig['projects']['json']['active']) { $sCfgfile=$this->_getConfigFile($sId); if (!$sCfgfile || !file_exists($sCfgfile)){ return false; } - $this->_aPrjConfig = json_decode(file_get_contents($this->_getConfigFile($sId)), true); + $_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); + return false; + } + $this->_aPrjConfig = $_aPrjConfigTmp; } if (isset($this->_aConfig['projects']['ldap']['active']) && $this->_aConfig['projects']['ldap']['active']) { // TODO: read project after saving it - @see $this->saveConfig() @@ -2748,6 +2759,19 @@ class project extends base { return $sReturn; } + /** + * return html code for current project errors by rendering a box per error in $this->_errors + * @return string + */ + public function renderErrorBoxes(){ + $sReturn=''; + if(count($this->_errors)){ + foreach($this->_errors as $sError){ + $sReturn.=$this->_oHtml->getBox("error", $sError); + } + } + return $sReturn; + } /** * render html for a colored link to any project action * @param string $sFunction name of the action; one of accept|build|cleanup|deploy|new|overview|phase|rollback|setup -- GitLab