diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2018-05-05 15:07:22 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2018-05-05 15:07:22 +0100 |
| commit | a6410500f0872b957a8d89f116e3328475633a80 (patch) | |
| tree | 50412b96720819179cde186850a7b7d2b38c4c25 /app/Http/Middleware/CheckForMaintenanceMode.php | |
| parent | 0f471f918d56a990950c039f6e0c4e38a26cc84a (diff) | |
| download | webtrees-a6410500f0872b957a8d89f116e3328475633a80.tar.gz webtrees-a6410500f0872b957a8d89f116e3328475633a80.tar.bz2 webtrees-a6410500f0872b957a8d89f116e3328475633a80.zip | |
Move site-offline to new framework
Diffstat (limited to 'app/Http/Middleware/CheckForMaintenanceMode.php')
| -rw-r--r-- | app/Http/Middleware/CheckForMaintenanceMode.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/app/Http/Middleware/CheckForMaintenanceMode.php b/app/Http/Middleware/CheckForMaintenanceMode.php new file mode 100644 index 0000000000..9097a862be --- /dev/null +++ b/app/Http/Middleware/CheckForMaintenanceMode.php @@ -0,0 +1,48 @@ +<?php +/** + * webtrees: online genealogy + * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>. + */ +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Http\Middleware; + +use Closure; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +/** + * Middleware to check whether the site is offline. + */ +class CheckForMaintenanceMode { + /** + * @param Request $request + * @param Closure $next + * + * @return Response + */ + public function handle(Request $request, Closure $next): Response { + $file = WT_ROOT . 'data/offline.txt'; + + if (file_exists($file)) { + $html = view('layouts/offline', [ + 'message' => file_get_contents($file), + 'url' => $request->getRequestUri(), + ]); + + return new Response($html, Response::HTTP_SERVICE_UNAVAILABLE); + } + + return $next($request); + } +} |
