summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/MergeRecordsAction.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-11-04 21:04:41 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-11-04 21:04:41 +0000
commit5bbfbb827763d1327d8312b88cb750c6dec7b775 (patch)
tree3b448290bca9cce926a535ebd9aaf006fc9b23ce /app/Http/RequestHandlers/MergeRecordsAction.php
parentc70b8181c83beebb552ccb4912863314eecdbf60 (diff)
downloadwebtrees-5bbfbb827763d1327d8312b88cb750c6dec7b775.tar.gz
webtrees-5bbfbb827763d1327d8312b88cb750c6dec7b775.tar.bz2
webtrees-5bbfbb827763d1327d8312b88cb750c6dec7b775.zip
Update routing in merge-records
Diffstat (limited to 'app/Http/RequestHandlers/MergeRecordsAction.php')
-rw-r--r--app/Http/RequestHandlers/MergeRecordsAction.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/app/Http/RequestHandlers/MergeRecordsAction.php b/app/Http/RequestHandlers/MergeRecordsAction.php
new file mode 100644
index 0000000000..68ca8a3818
--- /dev/null
+++ b/app/Http/RequestHandlers/MergeRecordsAction.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2019 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+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,
+ ]));
+ }
+}