Skip to content

Commit

Permalink
MVP bugfix SUBM/SUBN is not exported in HEAD. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefferson49 committed Oct 8, 2023
1 parent 6957e8e commit 40d7406
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
5 changes: 2 additions & 3 deletions DownloadGedcomWithURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\GedcomExportService;
use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Site;
use Fisharebest\Webtrees\Tree;
Expand Down Expand Up @@ -82,7 +81,7 @@ class DownloadGedcomWithURL extends AbstractModule implements
use ModuleCustomTrait;
use ModuleConfigTrait;

private GedcomExportService $gedcom_export_service;
private RemoteGedcomExportService $gedcom_export_service;

private GedcomSevenExportService $gedcom7_export_service;

Expand Down Expand Up @@ -133,7 +132,7 @@ public function __construct()
$response_factory = app(ResponseFactoryInterface::class);
$stream_factory = new Psr17Factory();

$this->gedcom_export_service = new GedcomExportService($response_factory, $stream_factory);
$this->gedcom_export_service = new RemoteGedcomExportService($response_factory, $stream_factory);
$this->gedcom7_export_service = new GedcomSevenExportService($response_factory, $stream_factory);
}

Expand Down
74 changes: 74 additions & 0 deletions RemoteGedcomExportService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2023 webtrees development team
* <http://webtrees.net>
* DownloadGedcomWithURL (webtrees custom module):
* Copyright (C) 2023 Markus Hemprich
* <http://www.familienforschung-hemprich.de>
*
* 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 <https://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace Jefferson49\Webtrees\Module\DownloadGedcomWithURL;

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Header;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\GedcomExportService;
use Fisharebest\Webtrees\Tree;


/**
* Export data in GEDCOM format
*/
class RemoteGedcomExportService extends GedcomExportService
{
/**
* Create a header record for a GEDCOM file, which exports SUBM/SUBN even if no user is logged in
*
* @param Tree $tree
* @param string $encoding
* @param bool $include_sub
*
* @return string
*/
public function createHeader(Tree $tree, string $encoding, bool $include_sub, int $access_level = null): string
{
//Take GEDCOM from parent method as a base
$gedcom = parent::createHeader($tree, $encoding, $include_sub);

$header = Registry::headerFactory()->make('HEAD', $tree) ?? Registry::headerFactory()->new('HEAD', '0 HEAD', null, $tree);

if ($header instanceof Header) {

if ($include_sub) {

//Apply access level of 'none', because the GEDCOM standard requires to include a submitter and export needs to be consistent if a submitter/submission exists
//Privacy of the submitter/submission is handled in the submitter/submission object itself
foreach ($header->facts(['SUBM', 'SUBN'], false, Auth::PRIV_HIDE) as $fact) {

//Add submitter/submission if the parent method did not find it, because of access rights
if (!str_contains($gedcom, "\n1 " . substr($fact->tag(), -4, 4))) {
$gedcom .= "\n" . $fact->gedcom();
}
}
}
}

return $gedcom;
}
}
1 change: 1 addition & 0 deletions module.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@

require __DIR__ . '/DownloadGedcomWithURL.php';
require __DIR__ . '/GedcomSevenExportService.php';
require __DIR__ . '/RemoteGedcomExportService.php';

return new DownloadGedcomWithURL();

0 comments on commit 40d7406

Please sign in to comment.