15bbfbb82SGreg Roach<?php 25bbfbb82SGreg Roach 35bbfbb82SGreg Roach/** 45bbfbb82SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 65bbfbb82SGreg Roach * This program is free software: you can redistribute it and/or modify 75bbfbb82SGreg Roach * it under the terms of the GNU General Public License as published by 85bbfbb82SGreg Roach * the Free Software Foundation, either version 3 of the License, or 95bbfbb82SGreg Roach * (at your option) any later version. 105bbfbb82SGreg Roach * This program is distributed in the hope that it will be useful, 115bbfbb82SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 125bbfbb82SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 135bbfbb82SGreg Roach * GNU General Public License for more details. 145bbfbb82SGreg 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/>. 165bbfbb82SGreg Roach */ 175bbfbb82SGreg Roach 185bbfbb82SGreg Roachdeclare(strict_types=1); 195bbfbb82SGreg Roach 205bbfbb82SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 215bbfbb82SGreg Roach 226b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 23b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 245bbfbb82SGreg Roachuse Psr\Http\Message\ResponseInterface; 255bbfbb82SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 265bbfbb82SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 275bbfbb82SGreg Roach 285bbfbb82SGreg Roachuse function redirect; 295bbfbb82SGreg Roachuse function route; 305bbfbb82SGreg Roach 315bbfbb82SGreg Roach/** 325bbfbb82SGreg Roach * Merge records 335bbfbb82SGreg Roach */ 345bbfbb82SGreg Roachclass MergeRecordsAction implements RequestHandlerInterface 355bbfbb82SGreg Roach{ 365bbfbb82SGreg Roach /** 375bbfbb82SGreg Roach * @param ServerRequestInterface $request 385bbfbb82SGreg Roach * 395bbfbb82SGreg Roach * @return ResponseInterface 405bbfbb82SGreg Roach */ 415bbfbb82SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 425bbfbb82SGreg Roach { 43b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 44748dbe15SGreg Roach $xref1 = Validator::parsedBody($request)->isXref()->string('xref1'); 45748dbe15SGreg Roach $xref2 = Validator::parsedBody($request)->isXref()->string('xref2'); 465bbfbb82SGreg Roach 475bbfbb82SGreg Roach // Merge record2 into record1 486b9cb339SGreg Roach $record1 = Registry::gedcomRecordFactory()->make($xref1, $tree); 496b9cb339SGreg Roach $record2 = Registry::gedcomRecordFactory()->make($xref2, $tree); 505bbfbb82SGreg Roach 515bbfbb82SGreg Roach if ( 525bbfbb82SGreg Roach $record1 === null || 535bbfbb82SGreg Roach $record2 === null || 545bbfbb82SGreg Roach $record1 === $record2 || 5502467d32SGreg Roach $record1->tag() !== $record2->tag() || 565bbfbb82SGreg Roach $record1->isPendingDeletion() || 575bbfbb82SGreg Roach $record2->isPendingDeletion() 585bbfbb82SGreg Roach ) { 595bbfbb82SGreg Roach return redirect(route(MergeRecordsPage::class, [ 605bbfbb82SGreg Roach 'tree' => $tree->name(), 615bbfbb82SGreg Roach 'xref1' => $xref1, 625bbfbb82SGreg Roach 'xref2' => $xref2, 635bbfbb82SGreg Roach ])); 645bbfbb82SGreg Roach } 655bbfbb82SGreg Roach 665bbfbb82SGreg Roach return redirect(route(MergeFactsPage::class, [ 675bbfbb82SGreg Roach 'tree' => $tree->name(), 685bbfbb82SGreg Roach 'xref1' => $xref1, 695bbfbb82SGreg Roach 'xref2' => $xref2, 705bbfbb82SGreg Roach ])); 715bbfbb82SGreg Roach } 725bbfbb82SGreg Roach} 73