15bbfbb82SGreg Roach<?php 25bbfbb82SGreg Roach 35bbfbb82SGreg Roach/** 45bbfbb82SGreg Roach * webtrees: online genealogy 55bbfbb82SGreg Roach * Copyright (C) 2019 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 155bbfbb82SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 165bbfbb82SGreg Roach */ 175bbfbb82SGreg Roach 185bbfbb82SGreg Roachdeclare(strict_types=1); 195bbfbb82SGreg Roach 205bbfbb82SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 215bbfbb82SGreg Roach 225bbfbb82SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 235bbfbb82SGreg Roachuse Fisharebest\Webtrees\Tree; 245bbfbb82SGreg Roachuse Psr\Http\Message\ResponseInterface; 255bbfbb82SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 265bbfbb82SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 275bbfbb82SGreg Roach 285bbfbb82SGreg Roachuse function assert; 295bbfbb82SGreg Roachuse function redirect; 305bbfbb82SGreg Roachuse function route; 315bbfbb82SGreg Roach 325bbfbb82SGreg Roach/** 335bbfbb82SGreg Roach * Merge records 345bbfbb82SGreg Roach */ 355bbfbb82SGreg Roachclass MergeRecordsAction implements RequestHandlerInterface 365bbfbb82SGreg Roach{ 375bbfbb82SGreg Roach /** 385bbfbb82SGreg Roach * @param ServerRequestInterface $request 395bbfbb82SGreg Roach * 405bbfbb82SGreg Roach * @return ResponseInterface 415bbfbb82SGreg Roach */ 425bbfbb82SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 435bbfbb82SGreg Roach { 445bbfbb82SGreg Roach $tree = $request->getAttribute('tree'); 455bbfbb82SGreg Roach assert($tree instanceof Tree); 465bbfbb82SGreg Roach 47*b46c87bdSGreg Roach $params = (array) $request->getParsedBody(); 48*b46c87bdSGreg Roach 49*b46c87bdSGreg Roach $xref1 = $params['xref1'] ?? ''; 50*b46c87bdSGreg Roach $xref2 = $params['xref2'] ?? ''; 515bbfbb82SGreg Roach 525bbfbb82SGreg Roach // Merge record2 into record1 535bbfbb82SGreg Roach $record1 = GedcomRecord::getInstance($xref1, $tree); 545bbfbb82SGreg Roach $record2 = GedcomRecord::getInstance($xref2, $tree); 555bbfbb82SGreg Roach 565bbfbb82SGreg Roach if ( 575bbfbb82SGreg Roach $record1 === null || 585bbfbb82SGreg Roach $record2 === null || 595bbfbb82SGreg Roach $record1 === $record2 || 605bbfbb82SGreg Roach $record1::RECORD_TYPE !== $record2::RECORD_TYPE || 615bbfbb82SGreg Roach $record1->isPendingDeletion() || 625bbfbb82SGreg Roach $record2->isPendingDeletion() 635bbfbb82SGreg Roach ) { 645bbfbb82SGreg Roach return redirect(route(MergeRecordsPage::class, [ 655bbfbb82SGreg Roach 'tree' => $tree->name(), 665bbfbb82SGreg Roach 'xref1' => $xref1, 675bbfbb82SGreg Roach 'xref2' => $xref2, 685bbfbb82SGreg Roach ])); 695bbfbb82SGreg Roach } 705bbfbb82SGreg Roach 715bbfbb82SGreg Roach return redirect(route(MergeFactsPage::class, [ 725bbfbb82SGreg Roach 'tree' => $tree->name(), 735bbfbb82SGreg Roach 'xref1' => $xref1, 745bbfbb82SGreg Roach 'xref2' => $xref2, 755bbfbb82SGreg Roach ])); 765bbfbb82SGreg Roach } 775bbfbb82SGreg Roach} 78