. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Module\CensusAssistantModule; 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 Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use function assert; /** * Edit the raw GEDCOM of a record. */ class EditRawRecordAction implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); $xref = $request->getParsedBody()['xref']; $facts = $request->getParsedBody()['fact'] ?? []; $fact_ids = $request->getParsedBody()['fact_id'] ?? []; $record = GedcomRecord::getInstance($xref, $tree); Auth::checkRecordAccess($record, true); $gedcom = '0 @' . $record->xref() . '@ ' . $record::RECORD_TYPE; // Retain any private facts foreach ($record->facts([], false, Auth::PRIV_HIDE) as $fact) { if (!in_array($fact->id(), $fact_ids, true) && !$fact->isPendingDeletion()) { $gedcom .= "\n" . $fact->gedcom(); } } // Append the updated facts foreach ($facts as $fact) { $gedcom .= "\n" . $fact; } // Empty lines and MSDOS line endings. $gedcom = preg_replace('/[\r\n]+/', "\n", $gedcom); $gedcom = trim($gedcom); $record->updateRecord($gedcom, false); return redirect($record->url()); } }