. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Factory; 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); $params = (array) $request->getParsedBody(); $xref1 = $params['xref1'] ?? ''; $xref2 = $params['xref2'] ?? ''; // Merge record2 into record1 $record1 = Factory::gedcomRecord()->make($xref1, $tree); $record2 = Factory::gedcomRecord()->make($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, ])); } }