summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/DataFixUpdate.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2020-01-15 10:52:18 +0000
committerGreg Roach <fisharebest@webtrees.net>2020-01-18 20:47:35 +0000
commitce42304a0e3b715b5830d587f136ecd5ca69f11b (patch)
tree3c151c2f3fd417c869d99f7a64e56c53d95c1b93 /app/Http/RequestHandlers/DataFixUpdate.php
parent94abcab717ff1468b211defdc77925d9590626ae (diff)
downloadwebtrees-ce42304a0e3b715b5830d587f136ecd5ca69f11b.tar.gz
webtrees-ce42304a0e3b715b5830d587f136ecd5ca69f11b.tar.bz2
webtrees-ce42304a0e3b715b5830d587f136ecd5ca69f11b.zip
Replace batch-update with data-fix modules. Add data-fix for _PRIM tags. Fixes: #1354, Fixes: #1370, Fixes: #1386, Fixes: #2931
Diffstat (limited to 'app/Http/RequestHandlers/DataFixUpdate.php')
-rw-r--r--app/Http/RequestHandlers/DataFixUpdate.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/app/Http/RequestHandlers/DataFixUpdate.php b/app/Http/RequestHandlers/DataFixUpdate.php
new file mode 100644
index 0000000000..a19ede67c4
--- /dev/null
+++ b/app/Http/RequestHandlers/DataFixUpdate.php
@@ -0,0 +1,78 @@
+<?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\Auth;
+use Fisharebest\Webtrees\GedcomRecord;
+use Fisharebest\Webtrees\Module\ModuleDataFixInterface;
+use Fisharebest\Webtrees\Services\ModuleService;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function assert;
+use function response;
+
+/**
+ * Run a data-fix.
+ */
+class DataFixUpdate implements RequestHandlerInterface
+{
+ /** @var ModuleService */
+ private $module_service;
+
+ /**
+ * DataFix constructor.
+ *
+ * @param ModuleService $module_service
+ */
+ public function __construct(ModuleService $module_service)
+ {
+ $this->module_service = $module_service;
+ }
+
+ /**
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $tree = $request->getAttribute('tree');
+ assert($tree instanceof Tree);
+
+ $data_fix = $request->getAttribute('data_fix', '');
+ $module = $this->module_service->findByName($data_fix);
+ assert($module instanceof ModuleDataFixInterface);
+
+ $xref = $request->getQueryParams()['xref'] ?? '';
+ $params = (array) $request->getQueryParams();
+
+ $record = GedcomRecord::getInstance($xref, $tree);
+ $record = Auth::checkRecordAccess($record, true);
+
+ if (!$record->isPendingDeletion() && $module->doesRecordNeedUpdate($record, $params)) {
+ $module->updateRecord($record, $params);
+ }
+
+ return response();
+ }
+}