From 3a8210bd271caad7fbcdebb7906fdc2a44f390a6 Mon Sep 17 00:00:00 2001 From: hahn <hahn@AAE49.campus.unibe.ch> Date: Fri, 14 Mar 2014 08:36:47 +0100 Subject: [PATCH] - FIX: include config for cronjob cron_deployment --- .../deployment/classes/project.class.php | 35 ++++++++----------- public_html/deployment/config/lang/de.json | 2 ++ public_html/deployment/inc_functions.php | 17 +++++---- public_html/deployment/index.php | 2 +- shellscripts/cron_deployment.php | 1 + 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index dbaabf08..d2fa2682 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -24,7 +24,7 @@ class project { * config file * @var string */ - private $_sCfgfile = "../config/inc_projects_config.php"; + // private $_sCfgfile = "../config/inc_projects_config.php"; /** * directory for project configs @@ -102,7 +102,7 @@ class project { * @return boolean */ private function _readConfig() { - require(__dir__ . '/' . $this->_sCfgfile); + global $aConfig; $this->_aConfig = $aConfig; return true; } @@ -328,14 +328,24 @@ class project { } $sInfoFile = $this->_getArchiveDir($sTimestamp) . '/' . $this->_aPrjConfig["fileprefix"] . '.json'; $aReturn['infofile'] = $sInfoFile; + $sPackageFile = $this->_getArchiveDir($sTimestamp) . '/' . $this->_aPrjConfig["fileprefix"] . '.tgz'; + $aReturn['packagefile'] = $sPackageFile; if (!file_exists($sInfoFile)) { $aReturn['error'] = sprintf(t("class-project-error-metafile-does-not-exist"), $sInfoFile); return $aReturn; - } + } $aJson = json_decode(file_get_contents($sInfoFile), true); if (is_array($aJson) && array_key_exists("version", $aJson)) { $aReturn = array_merge($aReturn, $aJson); $aReturn['ok'] = 1; + /* + if (!file_exists($sPackageFile)) { + $aReturn['error'] = sprintf(t("class-project-error-datafile-does-not-exist"), $sInfoFile); + } else { + $aReturn['filesizes']['packagefile']=filesize($sPackageFile); + } + * + */ return $aReturn; } $aReturn['error'] = sprintf(t("class-project-error-metafile-wrong-format"), $sInfoFile); @@ -834,22 +844,6 @@ class project { return $this->_sProcessTempOut; } - /** - * apply a config - * @param array $aConfig - * @return boolean - */ - public function setProjectById_OLD($sId) { - $this->_aPrjConfig = array(); - require(__dir__ . '/' . $this->_sCfgfile); - if (!array_key_exists("$sId", $aProjects)) { - die(sprintf(t("class-project-error-project-id-does-not-exist"), $sId)); - } - $this->_aPrjConfig = $aProjects[$sId]; - $this->_aConfig["id"] = $sId; - $this->_verifyConfig(); - return true; - } /** * apply a config @@ -857,8 +851,9 @@ class project { * @return boolean */ public function setProjectById($sId) { + global $aConfig; $this->_aPrjConfig = array(); - require(__dir__ . '/' . $this->_sCfgfile); +// require(__dir__ . '/' . $this->_sCfgfile); $this->_aConfig["id"] = $sId; diff --git a/public_html/deployment/config/lang/de.json b/public_html/deployment/config/lang/de.json index 75a53165..4aee169d 100644 --- a/public_html/deployment/config/lang/de.json +++ b/public_html/deployment/config/lang/de.json @@ -66,6 +66,7 @@ "class-project-error-command-failed": "Eines der Kommandos ist fehlgeschlagen (s.o.).<br>Frage ggf. den Administrator. Das Arbeitsverzeichnis " %s " wird für eine Analyse nicht gelöscht.", "class-project-error-getPhaseInfos-package-not-found": "Die Paket-Datei (.tgz) wurde nicht gefunden: %s", "class-project-error-getPhaseInfos-requires-phase": "Die Methode getPhaseInfos erfordert die Angabe eine Phase.", + "class-project-error-datafile-does-not-exist": "Die Paket-Datei "%s" existiert nicht.", "class-project-error-metafile-does-not-exist": "Die Datei mit den Metadaten "%s" existiert nicht.", "class-project-error-metafile-has-no-version": "Die Datei mit den Metadaten "%s" existiert, enthält aber keine Version. <pre>%s</pre>", "class-project-error-metafile-wrong-format": "Die Datei mit den Metadaten "%s" existiert, ist aber keine JSON Datei.", @@ -168,6 +169,7 @@ "accept": "Accept", "accept-hint": "Accept Phase [%s] und in die Queue von Phase [%s] stellen.", "all": "alle", + "archive": "Archiv", "build": "Build", "build-hint": "neues Paket erstellen und in Phase [%s] stellen.", "build-from": "Build vom", diff --git a/public_html/deployment/inc_functions.php b/public_html/deployment/inc_functions.php index ab758528..0d849957 100644 --- a/public_html/deployment/inc_functions.php +++ b/public_html/deployment/inc_functions.php @@ -10,6 +10,11 @@ 2013-11-08 Axel <axel.hahn@iml.unibe.ch> ###################################################################### */ + +if (!isset($aConfig) || !is_array($aConfig)){ + die("FATAL ERROR: \$aConfig does not exist. The config was not included before including ".__FILE__." in the request/ script.\n"); +} + global $aParams; $aParams = array(); @@ -69,14 +74,13 @@ function aHome($sClass = "btn") { * @return string */ function aPrjHome($sClass = "btn") { - global $aParams; + global $aParams, $aConfig; if (!array_key_exists("prj", $aParams)) return false; if ($aParams["prj"] == "all") return false; // if (!array_key_exists("action", $aParams)) return false; - require_once("./config/inc_projects_config.php"); require_once("./classes/project.class.php"); $oPrj = new project($aParams["prj"]); return '<a href="/deployment/' . $aParams["prj"] . '/" class="' . $sClass . '"><i class="icon-book"></i> ' . t("menu-project-home") . ' <strong>' . $oPrj->getLabel() . '</strong></a>'; @@ -88,9 +92,8 @@ function aPrjHome($sClass = "btn") { * @return type */ function getTopArea() { - global $aParams, $sImageBase, $aImages; + global $aParams, $sImageBase, $aImages, $aConfig; $sReturn = ''; - require_once("./config/inc_projects_config.php"); require_once("./classes/project.class.php"); require_once("./classes/projectlist.class.php"); @@ -243,6 +246,10 @@ function getAction() { function t($s) { global $aConfig; static $aLang = array(); + + if (!is_array($aConfig) || !array_key_exists("lang", $aConfig)){ + die("ERROR: \$aConfig[\"lang\"] does not exist.\n"); + } if (!count($aLang)) { $aLang = json_decode(file_get_contents(__DIR__ . "/config/lang/" . $aConfig["lang"] . ".json"), true); } @@ -283,5 +290,3 @@ function enterDeployinfos() { return $sOut; } - -?> diff --git a/public_html/deployment/index.php b/public_html/deployment/index.php index 71343fc2..da611b99 100644 --- a/public_html/deployment/index.php +++ b/public_html/deployment/index.php @@ -16,9 +16,9 @@ 2013-11-08 Axel <axel.hahn@iml.unibe.ch> ###################################################################### */ -require_once("./inc_functions.php"); require_once("./classes/page.class.php"); require_once("./config/inc_projects_config.php"); +require_once("./inc_functions.php"); $sPrj = ""; $sAction = "overview"; diff --git a/shellscripts/cron_deployment.php b/shellscripts/cron_deployment.php index 46510c08..70cd7563 100644 --- a/shellscripts/cron_deployment.php +++ b/shellscripts/cron_deployment.php @@ -9,6 +9,7 @@ // http://iml:deployment@ci.iml.unibe.ch/deployment/?prj=ci&action=deploy&par3=preview&confirm=1 $sDocroot = (dirname(__dir__)) . "/public_html"; +require_once("$sDocroot/deployment/config/inc_projects_config.php"); require_once("$sDocroot/deployment/classes/project.class.php"); $oPrj1 = new project(); -- GitLab