summaryrefslogtreecommitdiff
path: root/app/Functions/FunctionsImport.php
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2020-08-08 10:01:43 +0100
committerGreg Roach <greg@subaqua.co.uk>2020-08-08 10:05:33 +0100
commit42516cd6ea92a6870203fef61784b3ca06ce87ef (patch)
tree77beb07253717964baad682c4ca7ba5119416ad7 /app/Functions/FunctionsImport.php
parent14cb438872017cd90d7d7b58a9456a7a138b9d25 (diff)
downloadwebtrees-42516cd6ea92a6870203fef61784b3ca06ce87ef.tar.gz
webtrees-42516cd6ea92a6870203fef61784b3ca06ce87ef.tar.bz2
webtrees-42516cd6ea92a6870203fef61784b3ca06ce87ef.zip
Import co-ordinates from _PLAC_DEFN records
Diffstat (limited to 'app/Functions/FunctionsImport.php')
-rw-r--r--app/Functions/FunctionsImport.php49
1 files changed, 47 insertions, 2 deletions
diff --git a/app/Functions/FunctionsImport.php b/app/Functions/FunctionsImport.php
index 26f5255095..e624abd030 100644
--- a/app/Functions/FunctionsImport.php
+++ b/app/Functions/FunctionsImport.php
@@ -31,6 +31,7 @@ use Fisharebest\Webtrees\Location;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\Note;
use Fisharebest\Webtrees\Place;
+use Fisharebest\Webtrees\PlaceLocation;
use Fisharebest\Webtrees\Repository;
use Fisharebest\Webtrees\Services\GedcomService;
use Fisharebest\Webtrees\Soundex;
@@ -45,6 +46,7 @@ use function array_intersect_key;
use function array_map;
use function array_unique;
use function date;
+use function preg_match;
use function preg_match_all;
use function str_contains;
use function str_starts_with;
@@ -274,9 +276,9 @@ class FunctionsImport
if ($tree->getPreference('GENERATE_UIDS') === '1' && !str_contains($gedrec, "\n1 _UID ")) {
$gedrec .= "\n1 _UID " . GedcomTag::createUid();
}
- } elseif (preg_match('/0 (HEAD|TRLR)/', $gedrec, $match)) {
+ } elseif (preg_match('/0 (HEAD|TRLR|_PLAC_DEFN)/', $gedrec, $match)) {
$type = $match[1];
- $xref = $type; // For HEAD/TRLR, use type as pseudo XREF.
+ $xref = $type; // For records without an XREF, use the type as a pseudo XREF.
} else {
throw new GedcomErrorException($gedrec);
}
@@ -427,6 +429,10 @@ class FunctionsImport
}
break;
+ case '_PLAC_DEFN':
+ self::importLegacyPlacDefn($gedrec);
+ return;
+
default: // Custom record types.
DB::table('other')->insert([
'o_id' => $xref,
@@ -442,6 +448,45 @@ class FunctionsImport
}
/**
+ * Legacy Family Tree software generates _PLAC_DEFN records containing LAT/LONG values
+ *
+ * @param string $gedcom
+ */
+ private static function importLegacyPlacDefn(string $gedcom): void
+ {
+ $gedcom_service = new GedcomService();
+
+ if (preg_match('/\n1 PLAC (.+)/', $gedcom, $match)) {
+ $place_name = $match[1];
+ } else {
+ return;
+ }
+
+ if (preg_match('/\n3 LATI ([NS].+)/', $gedcom, $match)) {
+ $latitude = $gedcom_service->readLatitude($match[1]);
+ } else {
+ return;
+ }
+
+ if (preg_match('/\n3 LONG ([EW].+)/', $gedcom, $match)) {
+ $longitude = $gedcom_service->readLongitude($match[1]);
+ } else {
+ return;
+ }
+
+ $location = new PlaceLocation($place_name);
+
+ if ($location->latitude() === 0.0 && $location->longitude() === 0.0) {
+ DB::table('placelocation')
+ ->where('pl_id', '=', $location->id())
+ ->update([
+ 'pl_lati' => $latitude,
+ 'pl_long' => $longitude,
+ ]);
+ }
+ }
+
+ /**
* Extract all level 2 places from the given record and insert them into the places table
*
* @param string $xref