16ccdf4f0SGreg Roach<?php 23976b470SGreg Roach 36ccdf4f0SGreg Roach/** 46ccdf4f0SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 166ccdf4f0SGreg Roach */ 17fcfa147eSGreg 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{ 34c4943cffSGreg Roach private MigrationService $migration_service; 356ccdf4f0SGreg Roach 366ccdf4f0SGreg Roach /** 376ccdf4f0SGreg Roach * @param MigrationService $migration_service 386ccdf4f0SGreg Roach */ 396ccdf4f0SGreg Roach public function __construct(MigrationService $migration_service) 406ccdf4f0SGreg Roach { 416ccdf4f0SGreg Roach $this->migration_service = $migration_service; 426ccdf4f0SGreg Roach } 436ccdf4f0SGreg Roach 446ccdf4f0SGreg Roach /** 456ccdf4f0SGreg Roach * Update the database schema, if necessary. 466ccdf4f0SGreg Roach * 476ccdf4f0SGreg Roach * @param ServerRequestInterface $request 486ccdf4f0SGreg Roach * @param RequestHandlerInterface $handler 496ccdf4f0SGreg Roach * 506ccdf4f0SGreg Roach * @return ResponseInterface 516ccdf4f0SGreg Roach */ 526ccdf4f0SGreg Roach public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 536ccdf4f0SGreg Roach { 546ccdf4f0SGreg Roach $this->migration_service 556ccdf4f0SGreg Roach ->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION); 566ccdf4f0SGreg Roach 576ccdf4f0SGreg Roach return $handler->handle($request); 586ccdf4f0SGreg Roach } 596ccdf4f0SGreg Roach} 60