Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
e6674d60
Commit
e6674d60
authored
9 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
set deprecated marker for foreman class
parent
eea7a809
No related branches found
No related tags found
1 merge request
!66
php8 only; added variable types; short array syntax; remove glyphicons
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
public_html/deployment/classes/config-replacement.class.php
+189
-161
189 additions, 161 deletions
public_html/deployment/classes/config-replacement.class.php
public_html/deployment/classes/foremanapi.class.php
+2
-0
2 additions, 0 deletions
public_html/deployment/classes/foremanapi.class.php
with
191 additions
and
161 deletions
public_html/deployment/classes/config-replacement.class.php
+
189
−
161
View file @
e6674d60
...
...
@@ -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 {
/**
*
g
et an array with a flat list of all templatefiles of a build
*
G
et 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 {
}
/**
*
g
et effective hostgroup id of the current phase
*
G
et 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 {
}
/**
*
g
et foreman base url ... if foreman was activated in the setup
*
G
et 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
;
}
/**
*
s
et a phase of a project
*
S
et 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
);
...
...
This diff is collapsed.
Click to expand it.
public_html/deployment/classes/foremanapi.class.php
+
2
−
0
View file @
e6674d60
...
...
@@ -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']);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment