From 12115f73d155ad6b16ad77356d9e496e433477a8 Mon Sep 17 00:00:00 2001 From: hahn <axel.hahn@iml.unibe.ch> Date: Wed, 19 Dec 2018 15:38:03 +0100 Subject: [PATCH] task-2494 ... show templates of current project only --- .../classes/config-replacement.class.php | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/public_html/deployment/classes/config-replacement.class.php b/public_html/deployment/classes/config-replacement.class.php index cacacc6c..e8f9a675 100644 --- a/public_html/deployment/classes/config-replacement.class.php +++ b/public_html/deployment/classes/config-replacement.class.php @@ -101,6 +101,10 @@ class configreplacement { */ protected function _getForemanReplacement(){ global $aConfig; + + $sProject = $this->_oProject->getId(); + // echo "DEBUG: project id = $sProject<br>"; + if (!$this->_sPhase){ return false; } @@ -111,12 +115,12 @@ class configreplacement { } // return already cached result - if (array_key_exists($this->_sPhase, $this->_aForemanReplacements)){ - return $this->_aForemanReplacements[$this->_sPhase]; + if (array_key_exists($sProject, $this->_aForemanReplacements)){ + return $this->_aForemanReplacements[$sProject]; } // rebuilt - $this->_aForemanReplacements[$this->_sPhase]=false; + $this->_aForemanReplacements[$sProject]=false; $iEffectiveHostgroup=$this->getForemanHostgroup(); // abort if no hostgroup was set @@ -204,8 +208,12 @@ class configreplacement { $aYaml=spyc_load($sPart); // echo 'DEBUG: <pre>'.print_r($aYaml, 1).'</pre>'; - $aReturn=array(); - foreach ($aYaml as $aProject){ + + if (!isset($aYaml[$sProject])){ + return false; + } + foreach ($aYaml as $sPrjId=>$aProject){ + $aReturn=array(); foreach ($aProject as $sFile=>$aParams){ $aReturn[$sFile]=array(); if (array_key_exists('target', $aParams)){ @@ -222,17 +230,18 @@ class configreplacement { } } } + $this->_aForemanReplacements[$sPrjId]=array( + 'phase'=>$this->_sPhase, + 'rules'=>$aReturn, + 'host'=>$sHost, + 'yaml'=>$sPart, + 'hostgroup'=>$iEffectiveHostgroup, + 'hostsall'=>$aHosts, + 'hostsphase'=>$aHostsOfPhase, + ); } - $this->_aForemanReplacements[$this->_sPhase]=array( - 'rules'=>$aReturn, - 'host'=>$sHost, - 'yaml'=>$sPart, - 'hostgroup'=>$iEffectiveHostgroup, - 'hostsall'=>$aHosts, - 'hostsphase'=>$aHostsOfPhase, - ); - return $this->_aForemanReplacements[$this->_sPhase]; + return $this->_aForemanReplacements[$sProject]; } /** -- GitLab