From 1532392e7009f86593f112d60e905179a753f3dd Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 16 Mar 2021 09:51:52 +0200 Subject: [PATCH 1/5] Remove newline from end of version string --- model/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/Model.php b/model/Model.php index a3cc27383..25afce7f3 100644 --- a/model/Model.php +++ b/model/Model.php @@ -78,7 +78,7 @@ public function getVersion() { $ver = null; if (file_exists('.git')) { - $ver = shell_exec('git describe --tags --always'); + $ver = rtrim(shell_exec('git describe --tags --always')); } if ($ver === null) { From 98a7306f6604bbfcfe67ecd0669548598edcd95c Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 16 Mar 2021 09:52:59 +0200 Subject: [PATCH 2/5] Add meta tag for generator (Skosmos + version). Fixes #1116 --- model/Request.php | 9 +++++++++ view/meta.twig | 1 + 2 files changed, 10 insertions(+) diff --git a/model/Request.php b/model/Request.php index 24d73ac0f..b72bab594 100644 --- a/model/Request.php +++ b/model/Request.php @@ -266,4 +266,13 @@ public function getPlugins() { } return new PluginRegister($this->model->getConfig()->getGlobalPlugins()); } + + /** + * Return the version of this Skosmos installation, or "unknown" if + * it cannot be determined. The version information is based on Git tags. + * @return string version + */ + public function getVersion() { + return $this->model->getVersion(); + } } diff --git a/view/meta.twig b/view/meta.twig index d518c6ff4..2a1a00293 100644 --- a/view/meta.twig +++ b/view/meta.twig @@ -2,3 +2,4 @@ + From af5ba3b34efb8a6a797a90e3c59a0d7f99c82f05 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 16 Mar 2021 09:53:52 +0200 Subject: [PATCH 3/5] refactor: use version information from Request on about page --- controller/WebController.php | 2 -- view/about.twig | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/controller/WebController.php b/controller/WebController.php index bf6e50eea..afd972b56 100644 --- a/controller/WebController.php +++ b/controller/WebController.php @@ -305,12 +305,10 @@ public function invokeAboutPage($request) $template = $this->twig->loadTemplate('about.twig'); $this->setLanguageProperties($request->getLang()); $url = $request->getServerConstant('HTTP_HOST'); - $version = $this->model->getVersion(); echo $template->render( array( 'languages' => $this->languages, - 'version' => $version, 'server_instance' => $url, 'request' => $request, )); diff --git a/view/about.twig b/view/about.twig index 7bc8f6dca..8057e9989 100644 --- a/view/about.twig +++ b/view/about.twig @@ -15,6 +15,7 @@

{% if ServiceName != 'SERVICE_NAME' %}{{ ServiceName }}{% else %}Skosmos{% endif %} {% trans "layout designed by Hahmo" %}

+ {% set version = request.version %}

{% trans %}Skosmos version {{ version }}{% endtrans %}

From 0c4df1fc2c6114061ac41e83110702fa84a2b6de Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 16 Mar 2021 10:08:30 +0200 Subject: [PATCH 4/5] Add unit test for Request->getVersion method --- tests/RequestTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/RequestTest.php b/tests/RequestTest.php index b816bd705..7a432f750 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -158,4 +158,11 @@ public function testSetAndGetPage() { $this->assertEquals('index', $this->request->getPage()); } + /** + * @covers Request::getVersion + */ + public function testGetVersion() { + $version = $this->request->getVersion(); + $this->assertNotEmpty($version); + } } From 7ca6765a958261496eba20c849a8628f378c1989 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 16 Mar 2021 13:32:08 +0200 Subject: [PATCH 5/5] add return type declarations to getVersion methods --- model/Model.php | 2 +- model/Request.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/model/Model.php b/model/Model.php index 25afce7f3..4230ec8e0 100644 --- a/model/Model.php +++ b/model/Model.php @@ -74,7 +74,7 @@ public function getLogger() { * it cannot be determined. The version information is based on Git tags. * @return string version */ - public function getVersion() + public function getVersion() : string { $ver = null; if (file_exists('.git')) { diff --git a/model/Request.php b/model/Request.php index b72bab594..a8bee1558 100644 --- a/model/Request.php +++ b/model/Request.php @@ -272,7 +272,8 @@ public function getPlugins() { * it cannot be determined. The version information is based on Git tags. * @return string version */ - public function getVersion() { + public function getVersion() : string + { return $this->model->getVersion(); } }