From 5d8bf6b7881f56dff9e26c2f0d056fe1de9731e7 Mon Sep 17 00:00:00 2001 From: Oliver Raduner Date: Mon, 5 Feb 2018 00:22:20 +0100 Subject: [PATCH] [Bug #725] Zorg Code Version wird nun im Footer auf https://zorg.ch/ angezeigt --- www/includes/smarty.fnc.php | 2 +- www/includes/util.inc.php | 42 +++++++++++++++++++++++++++++++++ www/templates/layout/footer.tpl | 3 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/www/includes/smarty.fnc.php b/www/includes/smarty.fnc.php index 7a79a181..93e57f7f 100644 --- a/www/includes/smarty.fnc.php +++ b/www/includes/smarty.fnc.php @@ -1281,7 +1281,7 @@ function smarty_modifier_rendertime($mode='begin') ,'online_users' => array(var_online_users(), 'Usersystem', 'Array mit allen zur Zeit eingeloggten Usern', false) ,'num_new_events' => array(Events::getNumNewEvents(), 'Events', 'Zeigt Anzahl neu erstellter Events an', true) ,'login_error' => array($login_error, 'Usersystem', 'Ist leer oder enthält Fehlermeldung eines versuchten aber fehlgeschlagenen Logins eines Benutzers', false) - + ,'code_info' => array(getGitCodeVersion(), 'Code Info', 'Holt die aktuellen Code Infos (Version, last commit, etc.) aus dem Git HEAD', false) ); diff --git a/www/includes/util.inc.php b/www/includes/util.inc.php index 876442b3..6e4c9ab6 100644 --- a/www/includes/util.inc.php +++ b/www/includes/util.inc.php @@ -70,6 +70,20 @@ function timename($timestamp) { } +/** + * Funktion um ein Datum-Zeit String in einen Timestamp umzuweandeln + * @author IneX + * @date 04.02.2018 + * @param @datetime Must be valid full Date-Time String, e.g. 2016-03-11 11:00:00 + * @return string + */ +function datetimeToTimestamp($datetime) +{ + $d = new DateTime($datetime, new DateTimeZone('Europe/Zurich')); + return $d->getTimestamp(); +} + + function emailusername($username) { $username = strtolower($username); $username = str_replace("ä", "ae", $username); @@ -517,3 +531,31 @@ function urlExists($url) } return false; } + + +/** + * Get Code information from Git + * Usage: echo getGitVersion(); + * Result: MyApplication v1.2.3-dev.474a1d0 (2016-11-02 14:11:22) + * + * @author IneX + * @date 04.02.2018 + * @version 1.0 + * @link https://stackoverflow.com/a/33986403/5750030 + * @return array + */ +function getGitCodeVersion() +{ + try { + $codeVersion['version'] = trim(exec('git describe --tags --abbrev=0')); + $codeVersion['last_commit'] = trim(exec('git log --pretty="%h" -n1 HEAD')); + $lastCommitDatetime = trim(exec('git log -n1 --pretty=%ci HEAD')); + + $codeVersion['last_update'] = datetimeToTimestamp($lastCommitDatetime); + + return $codeVersion; + + } catch (Exception $e) { + error_log($e->getMessage()); + } +} diff --git a/www/templates/layout/footer.tpl b/www/templates/layout/footer.tpl index 0cd38cd8..9cff3121 100644 --- a/www/templates/layout/footer.tpl +++ b/www/templates/layout/footer.tpl @@ -21,6 +21,9 @@ [more] {/if}
Impressum | Privacy-Policy | Zorg Verein + {if $code_info.version != ''} + | Code Version: {$code_info.version}, {$code_info.last_commit} (updated: {$code_info.last_update|datename}){if $user->typ == 2} [view]{/if} + {/if}