Skip to content
Snippets Groups Projects
Commit e6674d60 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

set deprecated marker for foreman class

parent eea7a809
No related branches found
No related tags found
1 merge request!66php8 only; added variable types; short array syntax; remove glyphicons
......@@ -9,26 +9,40 @@ require_once 'project.class.php';
* config-replacement class
* reads templatefiles and scans its placeholders for replacements
*
* @deprecated It is used for Foreman replacements; TODO: remove this class
*
* @author hahn
*
* 2024-08-23 v1.1 Axel Hahn fix php parser problems
*/
class configreplacement {
class configreplacement
{
/**
* project class
* @var object
*/
protected $_oProject = false;
protected $_sPhase = false;
protected $_aForemanReplacements = false;
/**
* Phase of rollout
* @var string
*/
protected $_sPhase = '';
/**
* Found replacements in Foreman
* @var array
*/
protected array $_aForemanReplacements = [];
/**
* Constructor
* @param string $sProject optional: project id; you can use setProject() too
*/
public function __construct($sProject = '') {
public function __construct($sProject = '')
{
if ($sProject) {
$this->setProject($sProject);
}
......@@ -36,14 +50,15 @@ class configreplacement {
/**
* get an array with a flat list of all templatefiles of a build
* Get an array with a flat list of all templatefiles of a build
* @return boolean|array
*/
public function getTemplatefiles(){
public function getTemplatefiles(): bool|array
{
if (!$this->_sPhase) {
return false;
}
$aReturn = array();
$aReturn = [];
$aBuildfiles = $this->_oProject->getBuildfilesByPlace($this->_sPhase, 'onhold');
if (!$aBuildfiles) {
......@@ -63,7 +78,8 @@ class configreplacement {
* get an array with all template files (basename) and its replacement fields
* @return bool|array
*/
public function getReplacements(){
public function getReplacements(): bool|array
{
if (!$this->_sPhase) {
return false;
}
......@@ -72,7 +88,7 @@ class configreplacement {
return false;
}
$aReturn=array();
$aReturn = [];
foreach ($aFiles as $sFile) {
// $sFile always exists because it was read from filesystem
$sContent = file_get_contents($sFile);
......@@ -84,10 +100,11 @@ class configreplacement {
}
/**
* get effective hostgroup id of the current phase
* Get effective hostgroup id of the current phase
* @return integer
*/
public function getForemanHostgroup(){
public function getForemanHostgroup(): int
{
$aPrjConfig = $this->_oProject->getConfig();
$iForemanHostgroupDefault = (int) $aPrjConfig['deploy']['foreman']['hostgroup'];
$iForemanHostgroup = (int) $aPrjConfig['phases'][$this->_sPhase]['foreman-hostgroup'];
......@@ -96,10 +113,13 @@ class configreplacement {
/**
* get replacement definitions from foreman
*
* @global array $aConfig
*
* @return bool|array
*/
protected function _getForemanReplacement(){
protected function _getForemanReplacement(): bool|array
{
global $aConfig;
$sProject = $this->_oProject->getId();
......@@ -152,7 +172,8 @@ class configreplacement {
$sPhase = $bIsDemo ? 'demo' : $this->_sPhase;
foreach ($aHosts as $aName) {
$sName = $aName['name'];
if (($sPhase==='live' &&
if (
($sPhase === 'live' &&
(
strpos($sName, 'preview') === false
&& strpos($sName, 'stage') === false
......@@ -245,12 +266,13 @@ class configreplacement {
}
/**
* get foreman base url ... if foreman was activated in the setup
* Get foreman base url ... if foreman was activated in the setup
*
* @global array $aConfig ci config
* @return string
*/
private function _getForemanBaseUrl(){
private function _getForemanBaseUrl(): string
{
global $aConfig;
return (isset($aConfig['foreman']['api']))
? $aConfig['foreman']['api']
......@@ -264,7 +286,8 @@ class configreplacement {
*
* @return bool|string
*/
public function getForemanlink2Host(){
public function getForemanlink2Host(): bool|string
{
$sForemanurl = $this->_getForemanBaseUrl();
if (!$sForemanurl) {
return false;
......@@ -294,7 +317,8 @@ class configreplacement {
*
* @return bool|string
*/
public function getForemanlink2Hostgroup(){
public function getForemanlink2Hostgroup(): bool|string
{
$iEffectiveHostgroup = $this->getForemanHostgroup();
if ($iEffectiveHostgroup <= 0) {
return false;
......@@ -319,7 +343,8 @@ class configreplacement {
* get replacements in foreman
* @return bool|array
*/
public function getForemanReplacements(){
public function getForemanReplacements(): bool|array
{
return $this->_getForemanReplacement();
}
......@@ -327,20 +352,23 @@ class configreplacement {
* switch to a project
* @param string $sProject project id
* @param string $sPhase optional: a phase; one of preview|stage|live
* @return boolean
*/
public function setProject($sProject, $sPhase=false){
public function setProject(string $sProject, string $sPhase = ''): bool
{
$this->_oProject = new project($sProject);
$this->_aForemanReplacements=false;
$this->_aForemanReplacements = [];
$this->setPhase($sPhase);
return true;
}
/**
* set a phase of a project
* Set a phase of a project
* @param string $sPhase name of valid phase
* @return boolean
*/
public function setPhase($sPhase=false){
public function setPhase(string $sPhase = ''): bool
{
$this->_sPhase = false;
if (!$sPhase) {
$sPhase = $this->_oProject->getNextPhase(false);
......
......@@ -4,6 +4,8 @@
*
* foreman access to API
*
* @deprecated Foreman was too much hartcoded. TODO: remove this class
*
* @example
* in project class
* $oForeman=new ForemanApi($this->_aConfig['foreman']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment