From 3a9cbc08f4eeb0bedab8272f8ecdea169bd6313d Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Tue, 19 Jul 2022 16:59:28 +0200
Subject: [PATCH] code upates for php 8.1

---
 public_html/deployment/classes/cache.class.php     |  2 --
 .../classes/config-replacement.class.php           |  2 +-
 .../deployment/classes/foremanapi.class.php        |  4 ++--
 public_html/deployment/classes/formgen.class.php   |  2 +-
 public_html/deployment/classes/ldap.class.php      |  1 +
 public_html/deployment/classes/project.class.php   | 14 +++++++-------
 public_html/deployment/inc_functions.php           |  5 ++++-
 .../deployment/plugins/rollout/awx/rollout_awx.php |  4 ++--
 8 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/public_html/deployment/classes/cache.class.php b/public_html/deployment/classes/cache.class.php
index 471c578b..7077f416 100644
--- a/public_html/deployment/classes/cache.class.php
+++ b/public_html/deployment/classes/cache.class.php
@@ -491,5 +491,3 @@ class AhCache {
 }
 
 // ----------------------------------------------------------------------
-?>
-
diff --git a/public_html/deployment/classes/config-replacement.class.php b/public_html/deployment/classes/config-replacement.class.php
index e8f9a675..868967fb 100644
--- a/public_html/deployment/classes/config-replacement.class.php
+++ b/public_html/deployment/classes/config-replacement.class.php
@@ -115,7 +115,7 @@ class configreplacement {
         }
 
         // return already cached result
-        if (array_key_exists($sProject, $this->_aForemanReplacements)){
+        if (isset($this->_aForemanReplacements[$sProject])){
             return $this->_aForemanReplacements[$sProject];
         }
         
diff --git a/public_html/deployment/classes/foremanapi.class.php b/public_html/deployment/classes/foremanapi.class.php
index e0e9851e..75f5c501 100644
--- a/public_html/deployment/classes/foremanapi.class.php
+++ b/public_html/deployment/classes/foremanapi.class.php
@@ -154,7 +154,7 @@ class ForemanApi {
      */
     protected function log($sMessage, $sLevel = "info") {
         global $oCLog;
-        if($oCLog && method_exists($oLog, 'add')){
+        if(is_object($oCLog) && method_exists($oCLog, 'add')){
             return $oCLog->add(basename(__FILE__) . " class " . __CLASS__ . " - " . $sMessage, $sLevel);
         }
     }
@@ -326,7 +326,7 @@ class ForemanApi {
         
         
         // prevent missing data because of paging
-        if ($this->_aRequest['method']==='GET' && !array_key_exists('per_page', $this->_aRequest['filter'])){
+        if ($this->_aRequest['method']==='GET' && !isset($this->_aRequest['filter']['per_page'])){
             $this->_aRequest['filter']['per_page']=1000;
         }
         // TODO check postdata
diff --git a/public_html/deployment/classes/formgen.class.php b/public_html/deployment/classes/formgen.class.php
index 0e1ea574..f5ba5657 100644
--- a/public_html/deployment/classes/formgen.class.php
+++ b/public_html/deployment/classes/formgen.class.php
@@ -23,7 +23,7 @@ class formgen {
      * @return boolean
      */
     public function __construct($aNewFormData = array()) {
-        if (count($aNewFormData)){
+        if (is_array($aNewFormData) && count($aNewFormData)){
             return $this->setFormarray($aNewFormData);
         }
         return true;
diff --git a/public_html/deployment/classes/ldap.class.php b/public_html/deployment/classes/ldap.class.php
index d75e5971..49297e35 100644
--- a/public_html/deployment/classes/ldap.class.php
+++ b/public_html/deployment/classes/ldap.class.php
@@ -4,6 +4,7 @@
  * IML LDAP CONNECTOR FOR USER AUTHENTICATION
  *
  * @author axel.hahn@iml.unibe.ch
+ * 07-2017
  */
 class imlldap {
 
diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index 941ddc37..dab812e2 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -208,7 +208,7 @@ class project extends base {
      * @return boolean
      */
     private function _verifyConfig() {
-        if (!count($this->_aPrjConfig)){
+        if (!is_array($this->_aPrjConfig) || !count($this->_aPrjConfig)){
             // die(t("class-project-error-no-config"));
             throw new Exception(t("class-project-error-no-config"));
         }
@@ -1047,7 +1047,9 @@ class project extends base {
      */
     public function isActivePhase($sPhase) {
         return (
-                array_key_exists("active", $this->_aPrjConfig["phases"][$sPhase]) ? $this->_aPrjConfig["phases"][$sPhase]["active"][0] : false
+                $this->_aPrjConfig && isset($this->_aPrjConfig["phases"][$sPhase]["active"][0])
+                    ? $this->_aPrjConfig["phases"][$sPhase]["active"][0] 
+                    : false
                 );
     }
 
@@ -3321,10 +3323,8 @@ class project extends base {
                 'value' => false,
         );
         if (
-                array_key_exists('messenger', $this->_aConfig)
-                && array_key_exists('slack', $this->_aConfig['messenger'])
-                && array_key_exists('presets', $this->_aConfig['messenger']['slack'])
-                && count(array_key_exists('presets', $this->_aConfig['messenger']['slack']['presets']))
+                isset($this->_aConfig['messenger']['slack']['presets'])
+                && count($this->_aConfig['messenger']['slack']['presets'])
         ) {
             $aSelectSlack = array(
                 'type' => 'select',
@@ -3942,7 +3942,7 @@ class project extends base {
                 // 'required' => 'required',
                 'validate' => 'isastring',
                 'size' => 100,
-                'placeholder' => implode(", ", $this->_aConfig["phases"][$sPhase]["deploytimes"]),
+                'placeholder' => isset($this->_aConfig["phases"][$sPhase]["deploytimes"]) ? implode(", ", $this->_aConfig["phases"][$sPhase]["deploytimes"]) : '',
             );
             $aForms["setup"]["form"]['input' . $i++] = array(
                 'type' => 'markup',
diff --git a/public_html/deployment/inc_functions.php b/public_html/deployment/inc_functions.php
index ec157dd3..75b8ef4b 100644
--- a/public_html/deployment/inc_functions.php
+++ b/public_html/deployment/inc_functions.php
@@ -118,7 +118,10 @@ if (isset($_SERVER) && is_array($_SERVER) && array_key_exists("REQUEST_URI", $_S
      */
 
     foreach (array_keys($aParams) as $sKey) {
-        $aParams[$sKey] = str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $aParams[$sKey]);
+        $aParams[$sKey] = is_string($aParams[$sKey])
+            ? str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $aParams[$sKey])
+            : $aParams[$sKey]
+        ;
     }
 }
 
diff --git a/public_html/deployment/plugins/rollout/awx/rollout_awx.php b/public_html/deployment/plugins/rollout/awx/rollout_awx.php
index c9b315e1..a0df104b 100644
--- a/public_html/deployment/plugins/rollout/awx/rollout_awx.php
+++ b/public_html/deployment/plugins/rollout/awx/rollout_awx.php
@@ -87,7 +87,7 @@ class rollout_awx extends rollout_base {
      * [id] => array('value' => [ID], 'label' => [NAME] [ID])
      * @return array
      */
-    static public function getAwxInventories(){
+    public function getAwxInventories(){
         $aResponse=$this->_httpRequest(array(
                 'url'=>'/inventories/?order_by=name'.$this->_sAwxApiPaging,
                 'method'=>'GET',
@@ -128,7 +128,7 @@ class rollout_awx extends rollout_base {
      * [id] => array('value' => [ID], 'label' => [PLAYBOOK] [ID])
      * @return array
      */
-    static public function getAwxJobTemplates(){
+    public function getAwxJobTemplates(){
         $aResponse=$this->_httpRequest(array(
                 'url'=>'/job_templates/?order_by=name'.$this->_sAwxApiPaging,
                 'method'=>'GET',
-- 
GitLab