diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index dd56aceb4dae443f73a2400b2a40150453bc690e..98b08fd169f3e5d3dabbe9d066ac37c801742482 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -7,6 +7,7 @@ require_once __DIR__.'/../inc_functions.php'; require_once 'base.class.php'; require_once 'htmlguielements.class.php'; require_once 'messenger.class.php'; +require_once 'rollout_base.class.php'; /* ###################################################################### @@ -81,13 +82,25 @@ class project extends base { */ private $_iRcAll = 0; + + /** + * reference to html renderer class to draw output items + * @var object + */ protected $_oHtml = false; /** * object to access a version control, .e. git - * @var type + * @var object */ private $_oVcs = false; + + /** + * object for rollout + * @var type + */ + public $oRolloutPlugin = false; + private $_sBranchname = false; /** @@ -1096,6 +1109,12 @@ class project extends base { return $sNextPhase; } + /** + * get an array with deploy status ... + * 'inprogress'=>do versions differ from phase to phase = rollout of a version is in progress + 'hasQueue'=>is there a package in a queue (waiting for deployment time to get ready to be installed) + * @return array + */ public function getProgress(){ $this->getAllPhaseInfos(); return $this->_aData['progress']; @@ -1310,6 +1329,23 @@ class project extends base { return $this->_oVcs; } + /** + * get an array of enabled plugins + * @param string $sSection one of false|"rollout"|... + * @return array + */ + public function getConfiguredPlugins($sSection=false){ + $aReturn=array(); + if(!$sSection){ + $aReturn=$this->_aConfig["plugins"]; + } else { + foreach ($this->_aConfig["plugins"]["rollout"] as $sPluginName=>$aItem) { + $aReturn[$sPluginName] = $aItem; + } + } + return $aReturn; + } + /** * get a flat array of all existing ssh keys * @return array @@ -1435,6 +1471,27 @@ class project extends base { // echo "<pre>" . print_r($aData, true) . "</pre>"; $this->_verifyConfig(); + + // ----- init rollout plugin + // set name of the activated plugin for this project + $sPluginName=(isset($this->_aPrjConfig['deploy']['active_rollout_plugin']) && $this->_aPrjConfig['deploy']['active_rollout_plugin']) + ? $this->_aPrjConfig['deploy']['active_rollout_plugin'] + : 'default' + ; + $this->oRolloutPlugin = false; + try{ + require_once __DIR__.'/../plugins/rollout/'.$sPluginName.'/rollout_'.$sPluginName.'.php'; + $this->oRolloutPlugin = new rollout(array( + 'lang'=>$this->_aConfig['lang'], + 'phase'=>false, + 'globalcfg'=>$this->_aConfig['plugins']['rollout'][$sPluginName], + 'projectcfg'=>$this->_aPrjConfig, + )); + // print_r($this->_oRolloutPlugin->getPluginfos()); + // print_r($this->_oRolloutPlugin->getName()); + } catch (Exception $ex) { + + } return true; } diff --git a/public_html/deployment/classes/rollout.interface.php b/public_html/deployment/classes/rollout.interface.php new file mode 100644 index 0000000000000000000000000000000000000000..1c7ac6345db96b881b25c73516ca6f81088113e0 --- /dev/null +++ b/public_html/deployment/classes/rollout.interface.php @@ -0,0 +1,57 @@ +<?php +/** + * INTERFACE for rollout plugins + * + * @author hahn + */ +interface iRolloutplugin { + + // ---------------------------------------------------------------------- + // VERIFY + // ---------------------------------------------------------------------- + + /** + * check requirements if the plugin could work + */ + public function checkRequirements(); + + /** + * check access to a deploy target + */ + public function checkConnectionToTarget(); + + // ---------------------------------------------------------------------- + // SETTER + // ---------------------------------------------------------------------- + + // ---------------------------------------------------------------------- + // GETTER + // ---------------------------------------------------------------------- + + /** + * get configuration for the project .. or more specifi for a given phase + * @param string $sPhase + */ + public function getConfig($sPhase=false); + + /** + * get name of plugin as string ... language specific + */ + public function getName(); + + /** + * get description of plugin as string ... language specific + */ + public function getDescription(); + + /** + * get array of data in info.js + */ + public function getPluginInfos(); + + // ---------------------------------------------------------------------- + // ACTIONS + // ---------------------------------------------------------------------- + +} + diff --git a/public_html/deployment/classes/rollout_base.class.php b/public_html/deployment/classes/rollout_base.class.php new file mode 100644 index 0000000000000000000000000000000000000000..aec0070baeaca837832dcaffd71e6c0fd8b2a163 --- /dev/null +++ b/public_html/deployment/classes/rollout_base.class.php @@ -0,0 +1,232 @@ +<?php +require_once 'rollout.interface.php'; + +/** + * rollout_base class that will beextended in a rollout plugin + * + * @author axel + */ +class rollout_base implements iRolloutplugin{ + + /** + * identifier for current plugin; it us used to find the current plugin + * settings in the config structore for global and project based config + * @var string + */ + protected $_sPluginId='UNSET'; + /** + * data with plugin infos (read from info.json) + * @var array + */ + protected $_aPlugininfos=false; + + /** + * array with translation texts + * @var type + */ + protected $_aLang=false; + + /** + * set language; 2 letter code, i.e. "de"; default language is "en" ; a + * file "lang_en.json" is required in the plugin dir + * @var string + */ + protected $_sLang = 'en'; + + + protected $_sPhase = false; + + /** + * global configuration of the rollout plugin + * @var array + */ + protected $_aCfgGlobal = false; + /** + * configuration of the project + * @var array + */ + protected $_aCfgProject = false; + + /** + * initialize rollout plugin + * @param array $aParams hash with those possible keys + * lang string language, i.e. 'de' + * phase string name of phase in a project + * globalcfg array given global config $aConfig + * projectcfg array project config to generate config + * for project and all phases + * @return boolean + */ + public function __construct($aParams) { + + // set current plugin id - taken from plugin directory name above + $oReflection=new ReflectionClass($this); + $this->_sPluginId=basename(dirname($oReflection->getFileName())); + + // ----- init language + if (isset($aParams['lang'])){ + $this->setLang($aParams['lang']); + } else { + $this->setLang(); + } + + // ----- init phase + if (isset($aParams['phase'])){ + $this->setPhase($aParams['phase']); + } + + // ----- init global config + if (isset($aParams['globalcfg'])){ + $this->setGlobalConfig($aParams['globalcfg']); + } + // ----- init project config + if (isset($aParams['projectcfg'])){ + $this->setProjectConfig($aParams['projectcfg']); + } + return true; + } + + + + + /** + * get a translated text from lang_XX.json + * @see setLang() + * @param string $sKey key to find in lang file + * @return string + */ + private 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; + } + + /** + * set a phase for automatic use GETTER methods + */ + public function setPhase($sPhase){ + $this->_sPhase=$sPhase; + return true; + } + + + // ---------------------------------------------------------------------- + // INTERFACE :: CHECKS + // ---------------------------------------------------------------------- + + /** + * check requirements if the plugin could work + */ + public function checkRequirements(){ + // no specific checks needed ... always true + return true; + } + + /** + * check access to a deploy target + */ + public function checkConnectionToTarget(){ + // do nothing ... always true + return true; + } + + // ---------------------------------------------------------------------- + // INTERFACE :: SETTER + // ---------------------------------------------------------------------- + + + /** + * set Config ... by given global config of the current plugin + * @param array $aConfigArray + */ + public function setGlobalConfig($aConfigArray){ + return $this->_aCfgGlobal=$aConfigArray; + } + + + + /** + * set Config ... by given project config + */ + public function setProjectConfig($aProjectConfigArray){ + $this->_aCfgProject=$aProjectConfigArray; + + // ----- ensure that the config structure exists + // (it is easier fo handling in getConfig()) + if (!isset($this->_aCfgProject['deploy']['plugins'][$this->_sPluginId])){ + if (!isset($this->_aCfgProject['deploy']['plugins'])){ + if (!isset($this->_aCfgProject['deploy'])){ + $this->_aCfgProject['deploy']=array(); + } + $this->_aCfgProject['deploy']['plugins']=array(); + } + $this->_aCfgProject['deploy']['plugins'][$this->_sPluginId]=array(); + } + return $this->_aCfgProject; + } + + // ---------------------------------------------------------------------- + // INTERFACE :: GETTER + // ---------------------------------------------------------------------- + + /** + * get a hash with the merged config for project or mo specific: of a given + * phase + * @param string $sPhase + * @return array + */ + public function getConfig($sPhase=false){ + + return ($sPhase && isset($this->_aCfgProject['phases']['plugins'][$this->_sPluginId])) + ? array_merge($this->_aCfgGlobal, $this->_aCfgProject['deploy']['plugins'][$this->_sPluginId], $this->_aCfgProject['phases']['plugins'][$this->_sPluginId]) + : array_merge($this->_aCfgGlobal, $this->_aCfgProject['deploy']['plugins'][$this->_sPluginId]) + ; + } + + public function getName(){ + return $this->_t('plugin_name'); + } + + public function getDescription(){ + return $this->_t('description'); + } + /** + * get array read from info.json + * @return type + */ + public function getPluginInfos(){ + + if ($this->_aPlugininfos){ + return $this->_aPlugininfos; + } + + $oReflection=new ReflectionClass($this); + $sFile=dirname($oReflection->getFileName()) . '/info.json'; + $this->_aPlugininfos= (file_exists($sFile)) + ? json_decode(file_get_contents($sFile), 1) + : array('error'=> 'unable to read info file ['.$sFile.'].') + ; + return $this->_aPlugininfos; + } + +} diff --git a/public_html/deployment/pages/act_setup.php b/public_html/deployment/pages/act_setup.php index 701ee29ab20649dbc6207b100b296681d25ccf1b..6487e00f2dd31b483e17e149bd5e71b0b8a89ac7 100644 --- a/public_html/deployment/pages/act_setup.php +++ b/public_html/deployment/pages/act_setup.php @@ -304,7 +304,12 @@ if ($aParams["prj"] == "all") { // setup page of a an existing project // ------------------------------------------------------------ $oPrj = new project($aParams["prj"]); - // $sOut.='<div style="float: right">aParams:<pre>'.print_r($aParams, true).'</pre></div>'; + $sOut.='<div style="float: right">' + // . 'aParams:<pre>'.print_r($aParams, true).'</pre>' + . 'configured rollout plugins:<pre>'.print_r($oPrj->getConfiguredPlugins('rollout'), true).'</pre>' + // . 'rollout plugin infos:<pre>'.print_r($oPrj->oRolloutPlugin->getPluginInfos(), true).'</pre>' + . 'prj config of rollout plugin:<pre>'.print_r($oPrj->oRolloutPlugin->getConfig(), true).'</pre>' + . '</div>'; if (array_key_exists("setupaction", $aParams) && $aParams["setupaction"] == "save") { if ($oPrj->saveConfig()) { diff --git a/public_html/deployment/plugins/rollout/default/info.json b/public_html/deployment/plugins/rollout/default/info.json new file mode 100644 index 0000000000000000000000000000000000000000..b6f00239d4aeca148685ba6910b998995915184e --- /dev/null +++ b/public_html/deployment/plugins/rollout/default/info.json @@ -0,0 +1,16 @@ +{ + "name": "default", + "description": "Default rollout plugin - doing no action", + "author": "Axel Hahn; University odf Bern; Institute for Medical education", + + "version": "1.0", + "url": "[included]", + "license": "GNU GPL 3.0", + + "vars": { + "global": {}, + "project": {}, + "phase": {} + } +} + diff --git a/public_html/deployment/plugins/rollout/default/lang_de.json b/public_html/deployment/plugins/rollout/default/lang_de.json new file mode 100644 index 0000000000000000000000000000000000000000..0e2b0efb3d6d9a810c2a01c25fb73c9280bb08c1 --- /dev/null +++ b/public_html/deployment/plugins/rollout/default/lang_de.json @@ -0,0 +1,4 @@ +{ + "plugin_name": "Default: keine Aktion", + "description": "Es wird keine Aktion zum Rollout gestartet." +} \ No newline at end of file diff --git a/public_html/deployment/plugins/rollout/default/lang_en.json b/public_html/deployment/plugins/rollout/default/lang_en.json new file mode 100644 index 0000000000000000000000000000000000000000..9f0c03ef9dfba612949f2c484803cd404967faa0 --- /dev/null +++ b/public_html/deployment/plugins/rollout/default/lang_en.json @@ -0,0 +1,4 @@ +{ + "plugin_name": "Default: no action", + "description": "Doing nothing for rollout of a package." +} \ No newline at end of file diff --git a/public_html/deployment/plugins/rollout/default/rollout_default.php b/public_html/deployment/plugins/rollout/default/rollout_default.php new file mode 100644 index 0000000000000000000000000000000000000000..312ebf12e2e6e489affdef86a7d1144bc379012b --- /dev/null +++ b/public_html/deployment/plugins/rollout/default/rollout_default.php @@ -0,0 +1,28 @@ +<?php +/** + * + * Rollout plugin - default + * + * no action + * + * @author axel + */ +class rollout extends rollout_base { + + /** + * check requirements if the plugin could work + */ + public function checkRequirements(){ + // no specific checks needed ... always true + return true; + } + + /** + * check access to a deploy target + */ + public function checkConnectionToTarget(){ + // do nothing ... always true + return true; + } + +}