diff --git a/config/config_defaults.php b/config/config_defaults.php index 2b9906ebd3eafc9a12dd83b7036f518932b0b021..33c345eef335fad1617b6428ae5744a09b90223c 100644 --- a/config/config_defaults.php +++ b/config/config_defaults.php @@ -109,6 +109,10 @@ return [ // existing subkeys = enabled plugins // ---------------------------------------------------------------------- 'plugins'=>[ + 'build'=>[ + 'tgz'=>[], + 'zip'=>[], + ], 'rollout'=>[ 'default'=>[], /* diff --git a/public_html/deployment/classes/plugins.class.php b/public_html/deployment/classes/plugins.class.php new file mode 100644 index 0000000000000000000000000000000000000000..c314312f4b04ae5a485831eb6fcd659c8df02385 --- /dev/null +++ b/public_html/deployment/classes/plugins.class.php @@ -0,0 +1,191 @@ +<?php + +/** + * WIP + * base class for all plugin types to read available plugins + * and its metadata + * + * @example + * $CI_plugins=new ciplugins(); + * print_r($CI_plugins->getPluginTypes()); + * + * // $CI_plugins->setType('build'); + * // print_r($CI_plugins->getPlugins()); + * print_r($CI_plugins->getPlugins('build')); + * + * $CI_plugins->setPlugin('tgz'); + * + * + * @author axel + */ +class ciplugins { + + protected $_sPlugindir=false; + + /** + * @var string + */ + protected $_sType=false; + + /** + * @var string + */ + protected $_sPluginname=false; + + + protected $_sLang = "en-en"; + protected $_aLang = []; + + + // --------------------------------------------------------------- + // CONSTRUCTOR + // --------------------------------------------------------------- + + /** + * initialize plugins + * @return boolean + */ + public function __construct() { + + $this->_sPlugindir=dirname(__DIR__).'/plugins'; + + return true; + } + + // --------------------------------------------------------------- + // LANGUAGE TEXTS + // --------------------------------------------------------------- + + /** + * get a translated text from lang_XX.json in plugin dir; + * If the key is missed it returns "[KEY :: LANG]" + * + * @see setLang() + * @param string $sKey key to find in lang file + * @return string + */ + protected function _t($sKey){ + return (isset($this->_aLang[$sKey]) && $this->_aLang[$sKey]) + ? $this->_aLang[$sKey] + : "[ $sKey :: $this->_sLang ]" + ; + } + + /** + * set language for output of formdata and other texts. + * This method loads the language file into a hash. The output of + * translated texts can be done with $this->_t("your_key") + * + * @see _t() + * @param string $sLang language code, i.e. "de" + * @return boolean + */ + public function setLang($sLang=false){ + $this->_sLang=$sLang ? $sLang : $this->_sLang; + + $oReflection=new ReflectionClass($this); + $sFile=dirname($oReflection->getFileName()) . '/lang_'.$this->_sLang.'.json'; + $this->_aLang=(file_exists($sFile)) ? json_decode(file_get_contents($sFile), 1) : $this->_aLang; + return true; + } + // --------------------------------------------------------------- + // SETTER + // --------------------------------------------------------------- + + /** + * set a type for plugins ... what is a name of a subdir in the plugins directory + * @param {string} $sType Name of a plugin type, e.g. build|rollout + */ + public function setType($sType){ + if(!$sType || !is_dir($this->_sPlugindir.'/'.$sType)){ + return false; + } + return $this->_sType=$sType; + } + + /** + * set a plugin with autoload + * + * @param {string} $sPluginName name of the plugin + * @param {string} $sType optuional: set a type + * @return bool + */ + public function setPlugin($sPluginName,$sType=false){ + if($sType){ + if (!$this->setType($sType)){ + return false; + } + } + $sFile=$this->getPluginFilename($sPluginName); + if(!file_exists($sFile)){ + return false; + } + include_once $sFile; + return $this->_sPluginname=$sPluginName; + } + + // --------------------------------------------------------------- + // GETTER + // --------------------------------------------------------------- + + + /** + * get a location of a plugin file with full path + * The type must be initialized first with setType() + * + * @param string $sPluginName optional: Name of plugin + * @return string + */ + public function getPluginFilename($sPluginName=false){ + if(!$sPluginName){ + $sPluginName=$this->_sPluginname; + } + return $this->_sPlugindir.'/'.$this->_sType.'/'.$sPluginName.'/'.$this->_sType.'_'.$sPluginName.'.php'; + } + + + /** + * get an array of available plugin types read from filesystem + * @return array + */ + public function getPluginTypes(){ + $aReturn=[]; + foreach(glob($this->_sPlugindir.'/*', GLOB_ONLYDIR) as $sMydir){ + $aReturn[]=basename($sMydir); + } + return $aReturn; + } + + /** + * get an array of available plugins read from filesystem + * @return array + */ + public function getPlugins($sType=false){ + $aReturn=[]; + if($sType){ + if (!$this->setType($sType)){ + return $aReturn; + } + } + foreach(glob($this->_sPlugindir.'/'.$this->_sType.'/*', GLOB_ONLYDIR) as $sMydir){ + $aReturn[]=basename($sMydir); + } + return $aReturn; + } + + /** + * get a location of a plugin file with full path + * @param {bool} $bAutoload flag: autoload needed plugin file + * @return string + */ + public function getPluginClassname(){ + return $this->_sType.'_'.$this->_sPluginname; + } + + public function initPlugin(){ + $sClassname=$this->_sType.'_'.$this->_sPlugindir; + $TmpRolloutPlugin = new $sClassname([]); + + } + +} diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index 5e28c09bfd971d0e9f7c49d420775404db0dad22..730d799104a12e2f6129d177040679c1f72c5da7 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -9,6 +9,7 @@ require_once 'htmlguielements.class.php'; require_once 'messenger.class.php'; // plugins +// require_once 'plugins.class.php'; require_once 'build_base.class.php'; require_once 'rollout_base.class.php'; @@ -1364,7 +1365,7 @@ class project extends base { if(!$sSection){ $aReturn=$this->_aConfig["plugins"]; } else { - foreach ($this->_aConfig["plugins"]["rollout"] as $sPluginName=>$aItem) { + foreach ($this->_aConfig["plugins"][$sSection] as $sPluginName=>$aItem) { $aReturn[$sPluginName] = $aItem; } } @@ -2256,7 +2257,7 @@ class project extends base { $sReturn.=t("class-project-info-deploy-start-by-method-skip") . "<br>"; } else { - $sReturn.='<p>' . 'Plugin: '.$this->oRolloutPlugin->getId().'</p>'; + $sReturn.='<p>Plugin: '.$this->oRolloutPlugin->getId().'</p>'; foreach($this->oRolloutPlugin->getDeployCommands($sPhase) as $sCmd){ $sReturn.=$this->_execAndSend("$sCmd"); @@ -3423,6 +3424,50 @@ class project extends base { } } + // ---------- Build plugins + /* + + $aPluginsBuild = array( + 'select' => array( + 'type' => 'checkbox', + 'name' => 'build[enabled_build_plugins]', + 'label' => t("build-plugins"), + 'options' => [], + ), + // 'project-config' => '', + ); + foreach (array_keys($this->getConfiguredPlugins('build')) as $sPluginName){ + + $sPluginFile=$this->_getPluginFilename('build', $sPluginName); + $TmpRolloutPlugin = false; + $sMyClassname='build_'. $sPluginName; + if(file_exists($sPluginFile)){ + try{ + include_once $this->_getPluginFilename('build', $sPluginName); + $TmpRolloutPlugin = new $sMyClassname([]); + echo "FOUND $sMyClassname<br>"; + $aPluginsBuild['select']['options'][$sPluginName]=array( + 'label' => $TmpRolloutPlugin->getName(), + 'checked' => $bActive, + // 'onclick' => '$(\'.'.$sMyDivClass.'\').hide(); $(\'.' . $sMyDivClassActive . '\').show();', + ); + } catch (Exception $ex) { + + } + } else { + $aRollout['project-select']['options'][$sPluginName]=array( + 'label' => 'not found: <span class="error">' . $sMyClassname . '</span>', + 'checked' => false, + 'disabled' => "disabled", + ); + + + } + } + echo '<pre>'; print_r($aPluginsBuild); die(__METHOD__); + */ + + // ---------- /Build plugins // ---------- Rollout plugins $aRollout = array(