diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/Http/RequestHandlers/CheckForNewVersionNow.php | 54 | ||||
| -rw-r--r-- | app/Http/RequestHandlers/ControlPanel.php | 2 | ||||
| -rw-r--r-- | app/Http/Routes/WebRoutes.php | 2 | ||||
| -rw-r--r-- | app/Services/ServerCheckService.php | 3 | ||||
| -rw-r--r-- | app/Services/UpgradeService.php | 47 |
5 files changed, 97 insertions, 11 deletions
diff --git a/app/Http/RequestHandlers/CheckForNewVersionNow.php b/app/Http/RequestHandlers/CheckForNewVersionNow.php new file mode 100644 index 0000000000..ef387dd3e8 --- /dev/null +++ b/app/Http/RequestHandlers/CheckForNewVersionNow.php @@ -0,0 +1,54 @@ +<?php + +/** + * webtrees: online genealogy + * Copyright (C) 2022 webtrees development team + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Http\RequestHandlers; + +use Fisharebest\Webtrees\Registry; +use Fisharebest\Webtrees\Services\UpgradeService; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\RequestHandlerInterface; + +/** + * Check for a new version of webtrees. + */ +class CheckForNewVersionNow implements RequestHandlerInterface +{ + private UpgradeService $upgrade_service; + + /** + * @param UpgradeService $upgrade_service + */ + public function __construct(UpgradeService $upgrade_service) + { + $this->upgrade_service = $upgrade_service; + } + + /** + * @param ServerRequestInterface $request + * + * @return ResponseInterface + */ + public function handle(ServerRequestInterface $request): ResponseInterface + { + $this->upgrade_service->isUpgradeAvailable(true); + + return Registry::responseFactory()->response(); + } +} diff --git a/app/Http/RequestHandlers/ControlPanel.php b/app/Http/RequestHandlers/ControlPanel.php index c4e11e6fb4..072983e7ab 100644 --- a/app/Http/RequestHandlers/ControlPanel.php +++ b/app/Http/RequestHandlers/ControlPanel.php @@ -151,6 +151,8 @@ class ControlPanel implements RequestHandlerInterface 'server_errors' => $this->server_check_service->serverErrors(), 'server_warnings' => $this->server_check_service->serverWarnings(), 'latest_version' => $this->upgrade_service->latestVersion(), + 'latest_version_error' => $this->upgrade_service->latestVersionError(), + 'latest_version_timestamp' => $this->upgrade_service->latestVersionTimestamp(), 'all_users' => $this->user_service->all(), 'administrators' => $this->user_service->administrators(), 'managers' => $this->user_service->managers(), diff --git a/app/Http/Routes/WebRoutes.php b/app/Http/Routes/WebRoutes.php index 5b83bedd41..4bcf1b6c8f 100644 --- a/app/Http/Routes/WebRoutes.php +++ b/app/Http/Routes/WebRoutes.php @@ -62,6 +62,7 @@ use Fisharebest\Webtrees\Http\RequestHandlers\CalendarEvents; use Fisharebest\Webtrees\Http\RequestHandlers\CalendarPage; use Fisharebest\Webtrees\Http\RequestHandlers\ChangeFamilyMembersAction; use Fisharebest\Webtrees\Http\RequestHandlers\ChangeFamilyMembersPage; +use Fisharebest\Webtrees\Http\RequestHandlers\CheckForNewVersionNow; use Fisharebest\Webtrees\Http\RequestHandlers\CheckTree; use Fisharebest\Webtrees\Http\RequestHandlers\CleanDataFolder; use Fisharebest\Webtrees\Http\RequestHandlers\ContactAction; @@ -352,6 +353,7 @@ class WebRoutes ]); $router->get(ControlPanel::class, ''); + $router->post(CheckForNewVersionNow::class, '/check-now'); $router->get(BroadcastPage::class, '/broadcast/{to}'); $router->post(BroadcastAction::class, '/broadcast/{to}'); $router->get(CleanDataFolder::class, '/clean'); diff --git a/app/Services/ServerCheckService.php b/app/Services/ServerCheckService.php index f238047ac7..94f915189e 100644 --- a/app/Services/ServerCheckService.php +++ b/app/Services/ServerCheckService.php @@ -51,9 +51,8 @@ class ServerCheckService private const PHP_SUPPORT_URL = 'https://www.php.net/supported-versions.php'; private const PHP_MINOR_VERSION = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION; private const PHP_SUPPORT_DATES = [ - '7.4' => '2022-11-28', - '8.0' => '2023-11-26', '8.1' => '2024-11-25', + '8.2' => '2025-12-08', ]; // As required by illuminate/database 8.x diff --git a/app/Services/UpgradeService.php b/app/Services/UpgradeService.php index dc2beaae2b..817be1f871 100644 --- a/app/Services/UpgradeService.php +++ b/app/Services/UpgradeService.php @@ -20,9 +20,9 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Services; use Fig\Http\Message\StatusCodeInterface; +use Fisharebest\Webtrees\Contracts\TimestampInterface; use Fisharebest\Webtrees\Http\Exceptions\HttpServerErrorException; use Fisharebest\Webtrees\I18N; -use Fisharebest\Webtrees\Log; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Site; use Fisharebest\Webtrees\Webtrees; @@ -245,13 +245,15 @@ class UpgradeService } /** + * @param bool $force + * * @return bool */ - public function isUpgradeAvailable(): bool + public function isUpgradeAvailable(bool $force = false): bool { // If the latest version is unavailable, we will have an empty string which equates to version 0. - return version_compare(Webtrees::VERSION, $this->fetchLatestVersion()) < 0; + return version_compare(Webtrees::VERSION, $this->fetchLatestVersion($force)) < 0; } /** @@ -261,7 +263,7 @@ class UpgradeService */ public function latestVersion(): string { - $latest_version = $this->fetchLatestVersion(); + $latest_version = $this->fetchLatestVersion(false); [$version] = explode('|', $latest_version); @@ -269,13 +271,35 @@ class UpgradeService } /** + * What, if any, error did we have when fetching the latest version of webtrees. + * + * @return string + */ + public function latestVersionError(): string + { + return Site::getPreference('LATEST_WT_VERSION_ERROR'); + } + + /** + * When did we last try to fetch the latest version of webtrees. + * + * @return TimestampInterface + */ + public function latestVersionTimestamp(): TimestampInterface + { + $latest_version_wt_timestamp = (int) Site::getPreference('LATEST_WT_VERSION_TIMESTAMP'); + + return Registry::timestampFactory()->make($latest_version_wt_timestamp); + } + + /** * Where can we download the latest version of webtrees. * * @return string */ public function downloadUrl(): string { - $latest_version = $this->fetchLatestVersion(); + $latest_version = $this->fetchLatestVersion(false); [, , $url] = explode('|', $latest_version . '||'); @@ -305,19 +329,21 @@ class UpgradeService /** * Check with the webtrees.net server for the latest version of webtrees. * Fetching the remote file can be slow, so check infrequently, and cache the result. - * Pass the current versions of webtrees, PHP and MySQL, as the response + * Pass the current versions of webtrees, PHP and database, as the response * may be different for each. The server logs are used to generate * installation statistics which can be found at https://dev.webtrees.net/statistics.html * + * @param bool $force + * * @return string */ - private function fetchLatestVersion(): string + private function fetchLatestVersion(bool $force): string { $last_update_timestamp = (int) Site::getPreference('LATEST_WT_VERSION_TIMESTAMP'); $current_timestamp = time(); - if ($last_update_timestamp < $current_timestamp - self::CHECK_FOR_UPDATE_INTERVAL) { + if ($force || $last_update_timestamp < $current_timestamp - self::CHECK_FOR_UPDATE_INTERVAL) { try { $client = new Client([ 'timeout' => self::HTTP_TIMEOUT, @@ -330,11 +356,14 @@ class UpgradeService if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { Site::setPreference('LATEST_WT_VERSION', $response->getBody()->getContents()); Site::setPreference('LATEST_WT_VERSION_TIMESTAMP', (string) $current_timestamp); + Site::setPreference('LATEST_WT_VERSION_ERROR', ''); + } else { + Site::setPreference('LATEST_WT_VERSION_ERROR', 'HTTP' . $response->getStatusCode()); } } catch (GuzzleException $ex) { // Can't connect to the server? // Use the existing information about latest versions. - Log::addErrorLog('Cannot fetch latest webtrees version. ' . $ex->getMessage()); + Site::setPreference('LATEST_WT_VERSION_ERROR', $ex->getMessage()); } } |
