16ccdf4f0SGreg Roach<?php 23976b470SGreg Roach 36ccdf4f0SGreg Roach/** 46ccdf4f0SGreg Roach * webtrees: online genealogy 56ccdf4f0SGreg Roach * Copyright (C) 2019 webtrees development team 66ccdf4f0SGreg Roach * This program is free software: you can redistribute it and/or modify 76ccdf4f0SGreg Roach * it under the terms of the GNU General Public License as published by 86ccdf4f0SGreg Roach * the Free Software Foundation, either version 3 of the License, or 96ccdf4f0SGreg Roach * (at your option) any later version. 106ccdf4f0SGreg Roach * This program is distributed in the hope that it will be useful, 116ccdf4f0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 126ccdf4f0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136ccdf4f0SGreg Roach * GNU General Public License for more details. 146ccdf4f0SGreg Roach * You should have received a copy of the GNU General Public License 156ccdf4f0SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 166ccdf4f0SGreg Roach */ 17*fcfa147eSGreg Roach 186ccdf4f0SGreg Roachdeclare(strict_types=1); 196ccdf4f0SGreg Roach 206ccdf4f0SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware; 216ccdf4f0SGreg Roach 226ccdf4f0SGreg Roachuse Fisharebest\Webtrees\Services\MigrationService; 236ccdf4f0SGreg Roachuse Fisharebest\Webtrees\Webtrees; 246ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 256ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 266ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface; 276ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 286ccdf4f0SGreg Roach 296ccdf4f0SGreg Roach/** 306ccdf4f0SGreg Roach * Middleware to update the database automatically, after an upgrade. 316ccdf4f0SGreg Roach */ 326ccdf4f0SGreg Roachclass UpdateDatabaseSchema implements MiddlewareInterface 336ccdf4f0SGreg Roach{ 346ccdf4f0SGreg Roach /** @var MigrationService */ 356ccdf4f0SGreg Roach private $migration_service; 366ccdf4f0SGreg Roach 376ccdf4f0SGreg Roach /** 386ccdf4f0SGreg Roach * @param MigrationService $migration_service 396ccdf4f0SGreg Roach */ 406ccdf4f0SGreg Roach public function __construct(MigrationService $migration_service) 416ccdf4f0SGreg Roach { 426ccdf4f0SGreg Roach $this->migration_service = $migration_service; 436ccdf4f0SGreg Roach } 446ccdf4f0SGreg Roach 456ccdf4f0SGreg Roach /** 466ccdf4f0SGreg Roach * Update the database schema, if necessary. 476ccdf4f0SGreg Roach * 486ccdf4f0SGreg Roach * @param ServerRequestInterface $request 496ccdf4f0SGreg Roach * @param RequestHandlerInterface $handler 506ccdf4f0SGreg Roach * 516ccdf4f0SGreg Roach * @return ResponseInterface 526ccdf4f0SGreg Roach */ 536ccdf4f0SGreg Roach public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 546ccdf4f0SGreg Roach { 556ccdf4f0SGreg Roach $this->migration_service 566ccdf4f0SGreg Roach ->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION); 576ccdf4f0SGreg Roach 586ccdf4f0SGreg Roach return $handler->handle($request); 596ccdf4f0SGreg Roach } 606ccdf4f0SGreg Roach} 61