show available github release only if newer version exists (#4037)
This commit is contained in:
10
phpstan.neon
10
phpstan.neon
@@ -1066,11 +1066,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: src/Controller/DoctorController.php
|
path: src/Controller/DoctorController.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Method App\\\\Controller\\\\DoctorController\\:\\:getNextUpdateVersion\\(\\) return type has no value type specified in iterable type array\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Controller/DoctorController.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method App\\\\Controller\\\\DoctorController\\:\\:getPhpInfo\\(\\) return type has no value type specified in iterable type array\\.$#"
|
message: "#^Method App\\\\Controller\\\\DoctorController\\:\\:getPhpInfo\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@@ -6526,11 +6521,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: src/Utils/ReleaseVersion.php
|
path: src/Utils/ReleaseVersion.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Method App\\\\Utils\\\\ReleaseVersion\\:\\:getLatestReleaseFromGithub\\(\\) return type has no value type specified in iterable type array\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Utils/ReleaseVersion.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method App\\\\Utils\\\\ReleaseVersion\\:\\:getReleasesFromGithub\\(\\) return type has no value type specified in iterable type array\\.$#"
|
message: "#^Method App\\\\Utils\\\\ReleaseVersion\\:\\:getReleasesFromGithub\\(\\) return type has no value type specified in iterable type array\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Constants;
|
||||||
use App\Utils\FileHelper;
|
use App\Utils\FileHelper;
|
||||||
use App\Utils\PageSetup;
|
use App\Utils\PageSetup;
|
||||||
use App\Utils\ReleaseVersion;
|
use App\Utils\ReleaseVersion;
|
||||||
@@ -87,6 +88,13 @@ final class DoctorController extends AbstractController
|
|||||||
$page = new PageSetup('Doctor');
|
$page = new PageSetup('Doctor');
|
||||||
$page->setHelp('doctor.html');
|
$page->setHelp('doctor.html');
|
||||||
|
|
||||||
|
$latestRelease = $this->getNextUpdateVersion();
|
||||||
|
if (\is_array($latestRelease) && \array_key_exists('version', $latestRelease)) {
|
||||||
|
if (version_compare(Constants::VERSION, (string) $latestRelease['version']) >= 0) {
|
||||||
|
$latestRelease = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('doctor/index.html.twig', [
|
return $this->render('doctor/index.html.twig', [
|
||||||
'page_setup' => $page,
|
'page_setup' => $page,
|
||||||
'modules' => get_loaded_extensions(),
|
'modules' => get_loaded_extensions(),
|
||||||
@@ -100,7 +108,7 @@ final class DoctorController extends AbstractController
|
|||||||
'logLines' => $logLines,
|
'logLines' => $logLines,
|
||||||
'logSize' => $this->getLogSize(),
|
'logSize' => $this->getLogSize(),
|
||||||
'composer' => $this->getComposerPackages(),
|
'composer' => $this->getComposerPackages(),
|
||||||
'release' => $this->getNextUpdateVersion()
|
'release' => $latestRelease
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +117,7 @@ final class DoctorController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
private function getComposerPackages(): array
|
private function getComposerPackages(): array
|
||||||
{
|
{
|
||||||
|
/** @var array<string, string> $versions */
|
||||||
$versions = [];
|
$versions = [];
|
||||||
|
|
||||||
if (class_exists(InstalledVersions::class)) {
|
if (class_exists(InstalledVersions::class)) {
|
||||||
@@ -313,6 +322,9 @@ final class DoctorController extends AbstractController
|
|||||||
return $phpInfo;
|
return $phpInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{'version': string, 'date': \DateTimeInterface, 'url': string, 'download': string, 'content': string}|null
|
||||||
|
*/
|
||||||
private function getNextUpdateVersion(): ?array
|
private function getNextUpdateVersion(): ?array
|
||||||
{
|
{
|
||||||
return $this->cache->get('kimai.update_release', function (ItemInterface $item) {
|
return $this->cache->get('kimai.update_release', function (ItemInterface $item) {
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ final class ReleaseVersion
|
|||||||
* Get all releases from GitHub.
|
* Get all releases from GitHub.
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
|
* @return array|null
|
||||||
|
* @return array<string, array{'version': string, 'date': \DateTimeInterface, 'url': string, 'download': string, 'content': string}>
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getReleasesFromGithub(): array
|
private function getReleasesFromGithub(): array
|
||||||
@@ -93,7 +95,7 @@ final class ReleaseVersion
|
|||||||
* - content (string, release notes)
|
* - content (string, release notes)
|
||||||
*
|
*
|
||||||
* @param bool $compatible
|
* @param bool $compatible
|
||||||
* @return array|null
|
* @return array{'version': string, 'date': \DateTimeInterface, 'url': string, 'download': string, 'content': string}|null
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getLatestReleaseFromGithub(bool $compatible): ?array
|
public function getLatestReleaseFromGithub(bool $compatible): ?array
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
{% if release is not null and release is iterable %}
|
{% if release is not null and release is iterable %}
|
||||||
{% embed '@theme/embeds/card.html.twig' with release %}
|
{% embed '@theme/embeds/card.html.twig' with {'release': release, boxtype: 'warning'} %}
|
||||||
{% block box_title %}Kimai {{ release.version }} available (released on {{ release.date|date_short }}){% endblock %}
|
{% block box_title %}Kimai {{ release.version }} available (released on {{ release.date|date_short }}){% endblock %}
|
||||||
{% block box_body %}
|
{% block box_body %}
|
||||||
{{ release.content|md2html }}
|
{{ release.content|md2html }}
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ class DoctorControllerTest extends ControllerBaseTest
|
|||||||
$this->assertAccessIsGranted($client, '/doctor');
|
$this->assertAccessIsGranted($client, '/doctor');
|
||||||
|
|
||||||
$result = $client->getCrawler()->filter('.content .card-header');
|
$result = $client->getCrawler()->filter('.content .card-header');
|
||||||
self::assertCount(5, $result);
|
$counter = \count($result);
|
||||||
|
// this can contain a warning box, that a new release is available
|
||||||
|
self::assertTrue($counter === 6 || $counter === 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFlushLogWithInvalidCsrf()
|
public function testFlushLogWithInvalidCsrf()
|
||||||
|
|||||||
Reference in New Issue
Block a user