xref: /webtrees/app/Http/Middleware/CheckForNewVersion.php (revision f37874adb4bbe17ac1299f5fe92d2bcce003c198)
1*f37874adSGreg Roach<?php
2*f37874adSGreg Roach
3*f37874adSGreg Roach/**
4*f37874adSGreg Roach * webtrees: online genealogy
5*f37874adSGreg Roach * Copyright (C) 2022 webtrees development team
6*f37874adSGreg Roach * This program is free software: you can redistribute it and/or modify
7*f37874adSGreg Roach * it under the terms of the GNU General Public License as published by
8*f37874adSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*f37874adSGreg Roach * (at your option) any later version.
10*f37874adSGreg Roach * This program is distributed in the hope that it will be useful,
11*f37874adSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*f37874adSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*f37874adSGreg Roach * GNU General Public License for more details.
14*f37874adSGreg Roach * You should have received a copy of the GNU General Public License
15*f37874adSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16*f37874adSGreg Roach */
17*f37874adSGreg Roach
18*f37874adSGreg Roachdeclare(strict_types=1);
19*f37874adSGreg Roach
20*f37874adSGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware;
21*f37874adSGreg Roach
22*f37874adSGreg Roachuse Fig\Http\Message\RequestMethodInterface;
23*f37874adSGreg Roachuse Fisharebest\Webtrees\I18N;
24*f37874adSGreg Roachuse Fisharebest\Webtrees\Services\EmailService;
25*f37874adSGreg Roachuse Fisharebest\Webtrees\Services\UpgradeService;
26*f37874adSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
27*f37874adSGreg Roachuse Fisharebest\Webtrees\Site;
28*f37874adSGreg Roachuse Fisharebest\Webtrees\SiteUser;
29*f37874adSGreg Roachuse Psr\Http\Message\ResponseInterface;
30*f37874adSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
31*f37874adSGreg Roachuse Psr\Http\Server\MiddlewareInterface;
32*f37874adSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
33*f37874adSGreg Roachuse Throwable;
34*f37874adSGreg Roach
35*f37874adSGreg Roachuse function view;
36*f37874adSGreg Roach
37*f37874adSGreg Roach/**
38*f37874adSGreg Roach * Middleware to check if a new version of webtrees is available.
39*f37874adSGreg Roach */
40*f37874adSGreg Roachclass CheckForNewVersion implements MiddlewareInterface
41*f37874adSGreg Roach{
42*f37874adSGreg Roach    private UpgradeService $upgrade_service;
43*f37874adSGreg Roach
44*f37874adSGreg Roach    /**
45*f37874adSGreg Roach     * @param UpgradeService $upgrade_service
46*f37874adSGreg Roach     */
47*f37874adSGreg Roach    public function __construct(UpgradeService $upgrade_service)
48*f37874adSGreg Roach    {
49*f37874adSGreg Roach        $this->upgrade_service = $upgrade_service;
50*f37874adSGreg Roach    }
51*f37874adSGreg Roach
52*f37874adSGreg Roach    /**
53*f37874adSGreg Roach     * @param ServerRequestInterface  $request
54*f37874adSGreg Roach     * @param RequestHandlerInterface $handler
55*f37874adSGreg Roach     *
56*f37874adSGreg Roach     * @return ResponseInterface
57*f37874adSGreg Roach     */
58*f37874adSGreg Roach    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
59*f37874adSGreg Roach    {
60*f37874adSGreg Roach        // Only run on full page requests.
61*f37874adSGreg Roach        if ($request->getMethod() === RequestMethodInterface::METHOD_GET && $request->getHeaderLine('X-Requested-With') === '') {
62*f37874adSGreg Roach            $this->upgrade_service->isUpgradeAvailable();
63*f37874adSGreg Roach        }
64*f37874adSGreg Roach
65*f37874adSGreg Roach        return $handler->handle($request);
66*f37874adSGreg Roach    }
67*f37874adSGreg Roach}
68