xref: /webtrees/app/Http/Middleware/UpdateDatabaseSchema.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
16ccdf4f0SGreg Roach<?php
2*3976b470SGreg 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 */
176ccdf4f0SGreg Roachdeclare(strict_types=1);
186ccdf4f0SGreg Roach
196ccdf4f0SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware;
206ccdf4f0SGreg Roach
216ccdf4f0SGreg Roachuse Fisharebest\Webtrees\Services\MigrationService;
226ccdf4f0SGreg Roachuse Fisharebest\Webtrees\Webtrees;
236ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface;
246ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
256ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface;
266ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
276ccdf4f0SGreg Roach
286ccdf4f0SGreg Roach/**
296ccdf4f0SGreg Roach * Middleware to update the database automatically, after an upgrade.
306ccdf4f0SGreg Roach */
316ccdf4f0SGreg Roachclass UpdateDatabaseSchema implements MiddlewareInterface
326ccdf4f0SGreg Roach{
336ccdf4f0SGreg Roach    /** @var MigrationService */
346ccdf4f0SGreg Roach    private $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