. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; use function redirect; use function route; /** * Merge records */ class MergeRecordsAction implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); $xref1 = $request->getParsedBody()['xref1'] ?? ''; $xref2 = $request->getParsedBody()['xref2'] ?? ''; // Merge record2 into record1 $record1 = GedcomRecord::getInstance($xref1, $tree); $record2 = GedcomRecord::getInstance($xref2, $tree); if ( $record1 === null || $record2 === null || $record1 === $record2 || $record1::RECORD_TYPE !== $record2::RECORD_TYPE || $record1->isPendingDeletion() || $record2->isPendingDeletion() ) { return redirect(route(MergeRecordsPage::class, [ 'tree' => $tree->name(), 'xref1' => $xref1, 'xref2' => $xref2, ])); } return redirect(route(MergeFactsPage::class, [ 'tree' => $tree->name(), 'xref1' => $xref1, 'xref2' => $xref2, ])); } }