From 3546320419b03c47f842ae0d1bce6d35f9808588 Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Mon, 25 Jul 2022 09:53:26 +0200
Subject: [PATCH] fix build plugin extension

---
 public_html/deployment/classes/build_base.class.php    | 8 ++++----
 public_html/deployment/classes/project.class.php       | 9 +++++----
 public_html/deployment/plugins/build/zip/build_zip.php | 6 +++++-
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/public_html/deployment/classes/build_base.class.php b/public_html/deployment/classes/build_base.class.php
index 5f46ec49..bc9f3f00 100644
--- a/public_html/deployment/classes/build_base.class.php
+++ b/public_html/deployment/classes/build_base.class.php
@@ -108,7 +108,7 @@ class build_base implements iBuildplugin{
      * @return array
      */
     public function setOutfile($sOutFilename){
-        return $this->_sOutfile=$sOutFilename ? $sOutFilename.$this->getExtension() : $this->_sOutfile;
+        return $this->_sOutfile=$sOutFilename ? $sOutFilename : $this->_sOutfile;
     }
 
     // ---------------------------------------------------------------
@@ -184,15 +184,15 @@ class build_base implements iBuildplugin{
      */
     public function getExtension(){
         $aInfos=$this->getPluginInfos();
-        return isset($aInfos['extenmsion']) ? '.'.$aInfos['extenmsion'] : '';
+        return isset($aInfos['extension']) ? '.'.$aInfos['extension'] : '';
     }
     /**
-     * set outfile name
+     * set outfile name including extension (from plugin metadata)
      * @param  string  $sOutFilename  filename for output (without extension)
      * @return array
      */
     public function getOutfile(){
-        return $this->_sOutfile;
+        return $this->_sOutfile.$this->getExtension();
     }
     /**
      * set outfile name
diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index 90b8f3bd..5e28c09b 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -438,14 +438,14 @@ class project extends base {
     }
 
     /**
-     * get filename for package file (.tgz file)
+     * get filename for package file (without file extension)
      * @param string $sPhase  one of preview|stage|live ...
      * @param string $sPlace  one of onhold|ready2install|deployed
      * @return string
      */
     private function _getPackagefile($sPhase, $sPlace) {
         $sBase = $this->_getFileBase($sPhase, $sPlace);
-        return $sBase ? $sBase . '/' . $this->_aPrjConfig["fileprefix"] . '.tgz' : false;
+        return $sBase ? $sBase . '/' . $this->_aPrjConfig["fileprefix"] : false;
     }
 
     /**
@@ -477,6 +477,7 @@ class project extends base {
                     $sIcon = 'file-template';
                     break;
                 case 'tgz':
+                case 'zip':
                     $sType = 'package';
                     $sIcon = 'file-archive';
                     break;
@@ -3523,7 +3524,7 @@ class project extends base {
                     ),
                 ),
             );
-            if (count($aForemanHostgroups)) {
+            if ($aForemanHostgroups && count($aForemanHostgroups)) {
                 foreach ($aForemanHostgroups as $aItem) {
                     $bActive=$iForemanHostgroupDefault === (int) $aItem['id'];
                     $aSelectForemanGroups['options'][$aItem['id']] = array(
@@ -3865,7 +3866,7 @@ class project extends base {
                         ),
                     ),
                 );
-                if (count($aForemanHostgroups)) {
+                if (is_array($aForemanHostgroups) && count($aForemanHostgroups)) {
                     foreach ($aForemanHostgroups as $aItem) {
                         $aSelectForemanHostGroup['options'][$aItem['id']] = array(
                             'label' => $aItem['title'],
diff --git a/public_html/deployment/plugins/build/zip/build_zip.php b/public_html/deployment/plugins/build/zip/build_zip.php
index 37e7066f..2fadc359 100644
--- a/public_html/deployment/plugins/build/zip/build_zip.php
+++ b/public_html/deployment/plugins/build/zip/build_zip.php
@@ -20,11 +20,15 @@ class build_zip extends build_base {
     
     /**
      * get an array with shell commands to execute
+     * used zip params:
+     *   -9   compress better
+     *   -q   quiet operation
+     *   -r   recurse into directories
      * @return array
      */
     public function getBuildCommands(){
         return [
-            'cd "'. $this->getBuildDir(). '" && zip -r9 "'. $this->getOutfile().'" .'
+            'cd "'. $this->getBuildDir(). '" && zip -9qr "'. $this->getOutfile().'" .'
         ];
     }
    
-- 
GitLab