1bb03c9f0SGreg Roach<?php 2bb03c9f0SGreg Roach 3bb03c9f0SGreg Roach/** 4bb03c9f0SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6bb03c9f0SGreg Roach * This program is free software: you can redistribute it and/or modify 7bb03c9f0SGreg Roach * it under the terms of the GNU General Public License as published by 8bb03c9f0SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9bb03c9f0SGreg Roach * (at your option) any later version. 10bb03c9f0SGreg Roach * This program is distributed in the hope that it will be useful, 11bb03c9f0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12bb03c9f0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13bb03c9f0SGreg Roach * GNU General Public License for more details. 14bb03c9f0SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16bb03c9f0SGreg Roach */ 17bb03c9f0SGreg Roach 18bb03c9f0SGreg Roachdeclare(strict_types=1); 19bb03c9f0SGreg Roach 20bb03c9f0SGreg Roachnamespace Fisharebest\Webtrees\Factories; 21bb03c9f0SGreg Roach 22bb03c9f0SGreg Roachuse Fisharebest\Webtrees\Gedcom; 236b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 24bb03c9f0SGreg Roachuse Fisharebest\Webtrees\Tree; 25bb03c9f0SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 26bb03c9f0SGreg Roachuse Illuminate\Support\Collection; 27bb03c9f0SGreg Roach 28bb03c9f0SGreg Roach/** 29bb03c9f0SGreg Roach * Make a GedcomRecord object. 30bb03c9f0SGreg Roach */ 31bb03c9f0SGreg Roachabstract class AbstractGedcomRecordFactory 32bb03c9f0SGreg Roach{ 33bb03c9f0SGreg Roach /** 34bb03c9f0SGreg Roach * @param Tree $tree 35bb03c9f0SGreg Roach * 36*5fef3bfaSGreg Roach * @return Collection<array-key,string> 37bb03c9f0SGreg Roach */ 38bb03c9f0SGreg Roach protected function pendingChanges(Tree $tree): Collection 39bb03c9f0SGreg Roach { 4069c05a6eSGreg Roach // Caution - this cache can be overwritten by GedcomExportService 416b9cb339SGreg Roach return Registry::cache()->array()->remember(__CLASS__ . $tree->id(), static function () use ($tree): Collection { 42bb03c9f0SGreg Roach return DB::table('change') 43bb03c9f0SGreg Roach ->where('gedcom_id', '=', $tree->id()) 44bb03c9f0SGreg Roach ->where('status', '=', 'pending') 45bb03c9f0SGreg Roach ->orderBy('change_id') 46bb03c9f0SGreg Roach ->pluck('new_gedcom', 'xref'); 47bb03c9f0SGreg Roach }); 48bb03c9f0SGreg Roach } 49bb03c9f0SGreg Roach 50bb03c9f0SGreg Roach /** 51bb03c9f0SGreg Roach * We may have searched for X123, but found the record for x123. 52bb03c9f0SGreg Roach * 53bb03c9f0SGreg Roach * @param string $gedcom 54bb03c9f0SGreg Roach * @param string $xref 55bb03c9f0SGreg Roach * 5624f2a3afSGreg Roach * @return string 57bb03c9f0SGreg Roach */ 5824f2a3afSGreg Roach protected function extractXref(string $gedcom, string $xref): string 59bb03c9f0SGreg Roach { 60bb03c9f0SGreg Roach if (preg_match('/^0 @(' . Gedcom::REGEX_XREF . ')@/', $gedcom, $match)) { 61bb03c9f0SGreg Roach return $match[1]; 62bb03c9f0SGreg Roach } 63bb03c9f0SGreg Roach 64bb03c9f0SGreg Roach return $xref; 65bb03c9f0SGreg Roach } 66bb03c9f0SGreg Roach} 67