From 97ccb0cb21894a47c39a07036e59a7822075336f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Fri, 4 Aug 2023 23:55:41 +0200 Subject: [PATCH] Allow to globally disable update checking/connection with Github --- VERSION | 2 +- config/parameters.yaml | 2 ++ config/services.yaml | 4 ++++ src/Services/System/UpdateAvailableManager.php | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 9c6d6293..de023c91 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1 +1.7.0-dev diff --git a/config/parameters.yaml b/config/parameters.yaml index 27d720b0..4baf2fa7 100644 --- a/config/parameters.yaml +++ b/config/parameters.yaml @@ -23,6 +23,8 @@ parameters: partdb.users.use_gravatar: '%env(bool:USE_GRAVATAR)%' # Set to false, if no Gravatar images should be used for user profiles. partdb.users.email_pw_reset: '%env(bool:ALLOW_EMAIL_PW_RESET)%' # Config if users are able, to reset their password by email. By default this enabled, when a mail server is configured. + partdb.check_for_updates: true # Set to false, if Part-DB should not contact the GitHub API to check for updates + ###################################################################################################################### # Mail settings ###################################################################################################################### diff --git a/config/services.yaml b/config/services.yaml index a278ae78..24e6a6ac 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -315,6 +315,10 @@ services: arguments: $project_dir: '%kernel.project_dir%' + App\Services\System\UpdateAvailableManager: + arguments: + $check_for_updates: '%partdb.check_for_updates%' + #################################################################################################################### # Monolog #################################################################################################################### diff --git a/src/Services/System/UpdateAvailableManager.php b/src/Services/System/UpdateAvailableManager.php index 29da8cd4..bf44706d 100644 --- a/src/Services/System/UpdateAvailableManager.php +++ b/src/Services/System/UpdateAvailableManager.php @@ -39,7 +39,9 @@ class UpdateAvailableManager private const CACHE_KEY = 'uam_latest_version'; private const CACHE_TTL = 60 * 60 * 24 * 2; // 2 day - public function __construct(private readonly HttpClientInterface $httpClient, private readonly CacheInterface $updateCache, private readonly VersionManagerInterface $versionManager) + public function __construct(private readonly HttpClientInterface $httpClient, + private readonly CacheInterface $updateCache, private readonly VersionManagerInterface $versionManager, + private readonly bool $check_for_updates) { } @@ -77,6 +79,11 @@ class UpdateAvailableManager */ public function isUpdateAvailable(): bool { + //If we don't want to check for updates, we can return false + if (!$this->check_for_updates) { + return false; + } + $latestVersion = $this->getLatestVersion(); $currentVersion = $this->versionManager->getVersion(); @@ -90,6 +97,14 @@ class UpdateAvailableManager */ private function getLatestVersionInfo(): array { + //If we don't want to check for updates, we can return dummy data + if (!$this->check_for_updates) { + return [ + 'version' => '0.0.1', + 'url' => 'update-checking-disabled' + ]; + } + return $this->updateCache->get(self::CACHE_KEY, function (ItemInterface $item) { $item->expiresAfter(self::CACHE_TTL); $response = $this->httpClient->request('GET', self::API_URL);