1ce42304aSGreg Roach<?php 2ce42304aSGreg Roach 3ce42304aSGreg Roach/** 4ce42304aSGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6ce42304aSGreg Roach * This program is free software: you can redistribute it and/or modify 7ce42304aSGreg Roach * it under the terms of the GNU General Public License as published by 8ce42304aSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9ce42304aSGreg Roach * (at your option) any later version. 10ce42304aSGreg Roach * This program is distributed in the hope that it will be useful, 11ce42304aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12ce42304aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13ce42304aSGreg Roach * GNU General Public License for more details. 14ce42304aSGreg 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/>. 16ce42304aSGreg Roach */ 17ce42304aSGreg Roach 18ce42304aSGreg Roachdeclare(strict_types=1); 19ce42304aSGreg Roach 20ce42304aSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21ce42304aSGreg Roach 22ce42304aSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 23ce42304aSGreg Roachuse Fisharebest\Webtrees\I18N; 24ce42304aSGreg Roachuse Fisharebest\Webtrees\Module\ModuleDataFixInterface; 25ce42304aSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 26b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 27ce42304aSGreg Roachuse Psr\Http\Message\ResponseInterface; 28ce42304aSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29ce42304aSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30ce42304aSGreg Roach 31ce42304aSGreg Roachuse function e; 32ce42304aSGreg Roachuse function redirect; 33ce42304aSGreg Roachuse function route; 34ce42304aSGreg Roach 35ce42304aSGreg Roach/** 36ce42304aSGreg Roach * Run a data-fix. 37ce42304aSGreg Roach */ 38ce42304aSGreg Roachclass DataFixPage implements RequestHandlerInterface 39ce42304aSGreg Roach{ 40ce42304aSGreg Roach use ViewResponseTrait; 41ce42304aSGreg Roach 42c4943cffSGreg Roach private ModuleService $module_service; 43ce42304aSGreg Roach 44ce42304aSGreg Roach /** 45ce42304aSGreg Roach * @param ModuleService $module_service 46ce42304aSGreg Roach */ 47ce42304aSGreg Roach public function __construct(ModuleService $module_service) 48ce42304aSGreg Roach { 49ce42304aSGreg Roach $this->module_service = $module_service; 50ce42304aSGreg Roach } 51ce42304aSGreg Roach 52ce42304aSGreg Roach /** 53ce42304aSGreg Roach * @param ServerRequestInterface $request 54ce42304aSGreg Roach * 55ce42304aSGreg Roach * @return ResponseInterface 56ce42304aSGreg Roach */ 57ce42304aSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 58ce42304aSGreg Roach { 59b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 60ce42304aSGreg Roach 61ce42304aSGreg Roach $data_fixes = $this->module_service->findByInterface(ModuleDataFixInterface::class, false, true); 62ce42304aSGreg Roach 63ce42304aSGreg Roach if ($data_fixes->isEmpty()) { 64ce42304aSGreg Roach return redirect(route('control-panel')); 65ce42304aSGreg Roach } 66ce42304aSGreg Roach 67b55cbc6bSGreg Roach $data_fix = Validator::attributes($request)->string('data_fix', ''); 68ce42304aSGreg Roach $module = $this->module_service->findByName($data_fix); 69ce42304aSGreg Roach 70ce42304aSGreg Roach $this->layout = 'layouts/administration'; 71ce42304aSGreg Roach 72ce42304aSGreg Roach if ($module instanceof ModuleDataFixInterface) { 73ce42304aSGreg Roach $title = $module->title() . ' — ' . e($tree->title()); 74ce42304aSGreg Roach $page_url = route(self::class, ['data_fix' => $data_fix, 'tree' => $tree->name()]); 75ce42304aSGreg Roach $pending_url = route(PendingChanges::class, ['tree' => $tree->name(), 'url' => $page_url]); 76ce42304aSGreg Roach 77ce42304aSGreg Roach return $this->viewResponse('admin/data-fix-page', [ 78ce42304aSGreg Roach 'data_fix' => $module, 79ce42304aSGreg Roach 'title' => $title, 80ce42304aSGreg Roach 'tree' => $tree, 81ce42304aSGreg Roach 'pending_url' => $pending_url, 82ce42304aSGreg Roach ]); 83ce42304aSGreg Roach } 84ce42304aSGreg Roach 8510ee2e39SGreg Roach $title = I18N::translate('Data fixes') . ' — ' . e($tree->title()); 86ce42304aSGreg Roach 87ce42304aSGreg Roach return $this->viewResponse('admin/data-fix-select', [ 88ce42304aSGreg Roach 'title' => $title, 89ce42304aSGreg Roach 'data_fixes' => $data_fixes, 90ce42304aSGreg Roach 'tree' => $tree, 91ce42304aSGreg Roach ]); 92ce42304aSGreg Roach } 93ce42304aSGreg Roach} 94