2015-06-03 14:40:58 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */
|
2015-06-03 14:40:58 +02:00
|
|
|
|
2015-06-05 10:18:24 +02:00
|
|
|
namespace Icinga\Application;
|
2015-06-03 14:40:58 +02:00
|
|
|
|
2015-08-27 13:06:31 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the version of Icinga Web 2
|
|
|
|
*/
|
2015-06-03 14:40:58 +02:00
|
|
|
class Version
|
|
|
|
{
|
2018-04-25 13:02:47 +02:00
|
|
|
const VERSION = '2.5.2';
|
2015-06-05 12:38:55 +02:00
|
|
|
|
2015-06-03 14:40:58 +02:00
|
|
|
/**
|
|
|
|
* Get the version of this instance of Icinga Web 2
|
|
|
|
*
|
2015-06-05 12:38:55 +02:00
|
|
|
* @return array
|
2015-06-03 14:40:58 +02:00
|
|
|
*/
|
|
|
|
public static function get()
|
|
|
|
{
|
2015-06-05 12:38:55 +02:00
|
|
|
$version = array('appVersion' => self::VERSION);
|
2015-09-30 18:37:48 +02:00
|
|
|
if (false !== ($appVersion = @file_get_contents(Icinga::app()->getApplicationDir('VERSION')))) {
|
2015-06-05 12:38:55 +02:00
|
|
|
$matches = array();
|
|
|
|
if (@preg_match('/^(?P<gitCommitID>\w+) (?P<gitCommitDate>\S+)/', $appVersion, $matches)) {
|
2015-06-05 12:38:55 +02:00
|
|
|
return array_merge($version, $matches);
|
2015-06-05 12:38:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:14:14 +02:00
|
|
|
$gitCommitId = static::getGitHead(Icinga::app()->getBaseDir());
|
|
|
|
if ($gitCommitId !== false) {
|
|
|
|
$version['gitCommitID'] = $gitCommitId;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-09 14:19:32 +02:00
|
|
|
* Get the current commit of the Git repository in the given path
|
2016-09-01 10:14:14 +02:00
|
|
|
*
|
2016-09-09 14:19:32 +02:00
|
|
|
* @param string $repo Path to the Git repository
|
|
|
|
* @param bool $bare Whether the Git repository is bare
|
2016-09-01 10:14:14 +02:00
|
|
|
*
|
2016-09-09 14:19:32 +02:00
|
|
|
* @return string|bool False if not available
|
2016-09-01 10:14:14 +02:00
|
|
|
*/
|
2016-09-09 14:19:32 +02:00
|
|
|
public static function getGitHead($repo, $bare = false)
|
2016-09-01 10:14:14 +02:00
|
|
|
{
|
|
|
|
if (! $bare) {
|
2016-09-09 14:19:32 +02:00
|
|
|
$repo .= '/.git';
|
2016-09-01 10:14:14 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 14:19:32 +02:00
|
|
|
$head = @file_get_contents($repo . '/HEAD');
|
2015-09-23 15:53:10 +02:00
|
|
|
|
2016-09-09 14:19:32 +02:00
|
|
|
if ($head !== false) {
|
|
|
|
if (preg_match('/^ref: (.+)/', $head, $matches)) {
|
|
|
|
return @file_get_contents($repo . '/' . $matches[1]);
|
2015-06-05 12:38:55 +02:00
|
|
|
}
|
2016-09-09 14:19:32 +02:00
|
|
|
|
|
|
|
return $head;
|
2015-06-05 12:38:55 +02:00
|
|
|
}
|
|
|
|
|
2016-09-01 10:14:14 +02:00
|
|
|
return false;
|
2015-06-03 14:40:58 +02:00
|
|
|
}
|
|
|
|
}
|