From 757e993871f4409678bd3064d1bd40eb18cec3e6 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 3 Jun 2015 14:40:58 +0200 Subject: [PATCH] Outsource version-getting logic to Version::get() refs #9247 --- application/controllers/AboutController.php | 80 +-------------- application/views/scripts/about/index.phtml | 17 ++-- library/Icinga/Version.php | 105 ++++++++++++++++++++ 3 files changed, 116 insertions(+), 86 deletions(-) create mode 100644 library/Icinga/Version.php diff --git a/application/controllers/AboutController.php b/application/controllers/AboutController.php index 6572d7e8b..376490443 100644 --- a/application/controllers/AboutController.php +++ b/application/controllers/AboutController.php @@ -4,88 +4,12 @@ # namespace Icinga\Application\Controllers; use Icinga\Web\Controller\ActionController; -use Icinga\Application\Icinga; -use Icinga\Exception\IcingaException; +use Icinga\Version; class AboutController extends ActionController { public function indexAction() { - $this->view->appVersion = null; - $this->view->gitCommitID = null; - $this->view->gitCommitDate = null; - - if (false !== ($appVersion = @file( - Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION', - FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES - ))) { - foreach ($appVersion as $av) { - $matches = array(); - if (false === ($res = preg_match( - '/(?view->gitCommitID !== null) { - break; - } - - $matches2 = array(); - if (false === ($res = preg_match( - '/(?view->gitCommitID = $matches2[1]; - if (! isset($matches2[2])) { - break; - } - - foreach (preg_split( - '/\s*,\s*/', $matches2[2], -1, PREG_SPLIT_NO_EMPTY - ) as $refName) { - $matches3 = array(); - if (false === ($res = preg_match( - '/(?view->appVersion = $matches3[1]; - break; - } - } - break; - case 'GitCommitDate': - if ($this->view->gitCommitDate !== null) { - break; - } - - $matches2 = array(); - if (false === ($res = preg_match( - '/(?view->gitCommitDate = $matches2[1]; - } - } - } - } + $this->view->version = Version::get(); } } diff --git a/application/views/scripts/about/index.phtml b/application/views/scripts/about/index.phtml index 0429a5374..3c37a5e73 100644 --- a/application/views/scripts/about/index.phtml +++ b/application/views/scripts/about/index.phtml @@ -2,14 +2,15 @@

Icinga Web 2

translate('Version: %s'), $appVersion), - array($this->translate('Git commit ID: %s'), $gitCommitID), - array($this->translate('Git commit date: %s'), $gitCommitDate) - ) as $version) { - list($label, $value) = $version; - if ($value !== null) { - $versionInfo[] = sprintf($label, htmlspecialchars($value)); + if ($version !== false) { + foreach (array( + 'appVersion' => $this->translate('Version: %s'), + 'gitCommitID' => $this->translate('Git commit ID: %s'), + 'gitCommitDate' => $this->translate('Git commit date: %s') + ) as $key => $label) { + if (null !== ($value = $version[$key])) { + $versionInfo[] = sprintf($label, htmlspecialchars($value)); + } } } ?> diff --git a/library/Icinga/Version.php b/library/Icinga/Version.php new file mode 100644 index 000000000..130e75060 --- /dev/null +++ b/library/Icinga/Version.php @@ -0,0 +1,105 @@ + null, + 'gitCommitID' => null, + 'gitCommitDate' => null + ); + + if (false !== ($appVersion = @file( + Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION', + FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES + ))) { + foreach ($appVersion as $av) { + $matches = array(); + if (false === ($res = preg_match( + '/(?