. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Module\ModuleDataFixInterface; use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\Validator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function redirect; use function route; /** * Run a data-fix. */ class DataFixSelect implements RequestHandlerInterface { private ModuleService $module_service; /** * @param ModuleService $module_service */ public function __construct(ModuleService $module_service) { $this->module_service = $module_service; } /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = Validator::attributes($request)->tree(); $data_fixes = $this->module_service->findByInterface(ModuleDataFixInterface::class); $data_fix = Validator::parsedBody($request)->string('data_fix'); $module = $data_fixes->get($data_fix); if ($module instanceof ModuleDataFixInterface) { return redirect(route(DataFixPage::class, ['tree' => $tree->name(), 'data_fix' => $module->name()])); } return redirect(route(DataFixPage::class, ['tree' => $tree->name()])); } }