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