. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fisharebest\Webtrees\Services\MigrationService; use Fisharebest\Webtrees\Webtrees; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; /** * Middleware to update the database automatically, after an upgrade. */ class UpdateDatabaseSchema implements MiddlewareInterface { private MigrationService $migration_service; /** * @param MigrationService $migration_service */ public function __construct(MigrationService $migration_service) { $this->migration_service = $migration_service; } /** * Update the database schema, if necessary. * * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $this->migration_service ->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION); return $handler->handle($request); } }