1*6ccdf4f0SGreg Roach<?php 2*6ccdf4f0SGreg Roach/** 3*6ccdf4f0SGreg Roach * webtrees: online genealogy 4*6ccdf4f0SGreg Roach * Copyright (C) 2019 webtrees development team 5*6ccdf4f0SGreg Roach * This program is free software: you can redistribute it and/or modify 6*6ccdf4f0SGreg Roach * it under the terms of the GNU General Public License as published by 7*6ccdf4f0SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8*6ccdf4f0SGreg Roach * (at your option) any later version. 9*6ccdf4f0SGreg Roach * This program is distributed in the hope that it will be useful, 10*6ccdf4f0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*6ccdf4f0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*6ccdf4f0SGreg Roach * GNU General Public License for more details. 13*6ccdf4f0SGreg Roach * You should have received a copy of the GNU General Public License 14*6ccdf4f0SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15*6ccdf4f0SGreg Roach */ 16*6ccdf4f0SGreg Roachdeclare(strict_types=1); 17*6ccdf4f0SGreg Roach 18*6ccdf4f0SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware; 19*6ccdf4f0SGreg Roach 20*6ccdf4f0SGreg Roachuse Fisharebest\Webtrees\Services\MigrationService; 21*6ccdf4f0SGreg Roachuse Fisharebest\Webtrees\Webtrees; 22*6ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 23*6ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 24*6ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface; 25*6ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 26*6ccdf4f0SGreg Roach 27*6ccdf4f0SGreg Roach/** 28*6ccdf4f0SGreg Roach * Middleware to update the database automatically, after an upgrade. 29*6ccdf4f0SGreg Roach */ 30*6ccdf4f0SGreg Roachclass UpdateDatabaseSchema implements MiddlewareInterface 31*6ccdf4f0SGreg Roach{ 32*6ccdf4f0SGreg Roach /** @var MigrationService */ 33*6ccdf4f0SGreg Roach private $migration_service; 34*6ccdf4f0SGreg Roach 35*6ccdf4f0SGreg Roach /** 36*6ccdf4f0SGreg Roach * @param MigrationService $migration_service 37*6ccdf4f0SGreg Roach */ 38*6ccdf4f0SGreg Roach public function __construct(MigrationService $migration_service) 39*6ccdf4f0SGreg Roach { 40*6ccdf4f0SGreg Roach $this->migration_service = $migration_service; 41*6ccdf4f0SGreg Roach } 42*6ccdf4f0SGreg Roach 43*6ccdf4f0SGreg Roach /** 44*6ccdf4f0SGreg Roach * Update the database schema, if necessary. 45*6ccdf4f0SGreg Roach * 46*6ccdf4f0SGreg Roach * @param ServerRequestInterface $request 47*6ccdf4f0SGreg Roach * @param RequestHandlerInterface $handler 48*6ccdf4f0SGreg Roach * 49*6ccdf4f0SGreg Roach * @return ResponseInterface 50*6ccdf4f0SGreg Roach */ 51*6ccdf4f0SGreg Roach public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 52*6ccdf4f0SGreg Roach { 53*6ccdf4f0SGreg Roach $this->migration_service 54*6ccdf4f0SGreg Roach ->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION); 55*6ccdf4f0SGreg Roach 56*6ccdf4f0SGreg Roach return $handler->handle($request); 57*6ccdf4f0SGreg Roach } 58*6ccdf4f0SGreg Roach} 59