Skip to content

Commit

Permalink
Update PHP dependencies, and Fix: #5102, multi-row inserts break with…
Browse files Browse the repository at this point in the history
… Laravel 11.37.0
  • Loading branch information
fisharebest committed Jan 12, 2025
1 parent 78f3caf commit dfe98cc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 93 deletions.
69 changes: 8 additions & 61 deletions app/Services/GedcomImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\DB;
use Fisharebest\Webtrees\Elements\UnknownElement;
use Fisharebest\Webtrees\Exceptions\GedcomErrorException;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Gedcom;
Expand All @@ -45,6 +44,7 @@
use function array_intersect_key;
use function array_map;
use function array_unique;
use function array_values;
use function date;
use function explode;
use function max;
Expand All @@ -53,6 +53,7 @@
use function preg_match_all;
use function preg_replace;
use function round;
use function serialize;
use function str_contains;
use function str_replace;
use function str_starts_with;
Expand All @@ -71,11 +72,6 @@ class GedcomImportService
{
/**
* Tidy up a gedcom record on import, so that we can access it consistently/efficiently.
*
* @param string $rec
* @param Tree $tree
*
* @return string
*/
private function reformatRecord(string $rec, Tree $tree): string
{
Expand Down Expand Up @@ -230,7 +226,6 @@ private function reformatRecord(string $rec, Tree $tree): string
* @param Tree $tree import the record into this tree
* @param bool $update whether this is an updated record that has been accepted
*
* @return void
* @throws GedcomErrorException
*/
public function importRecord(string $gedrec, Tree $tree, bool $update): void
Expand Down Expand Up @@ -443,8 +438,6 @@ public function importRecord(string $gedrec, Tree $tree, bool $update): void

/**
* Legacy Family Tree software generates _PLAC_DEFN records containing LAT/LONG values
*
* @param string $gedcom
*/
private function importLegacyPlacDefn(string $gedcom): void
{
Expand Down Expand Up @@ -481,9 +474,7 @@ private function importLegacyPlacDefn(string $gedcom): void
}

/**
* Legacy Family Tree software generates _PLAC records containing LAT/LONG values
*
* @param string $gedcom
* TNG generates _PLAC records containing LAT/LONG values
*/
private function importTNGPlac(string $gedcom): void
{
Expand Down Expand Up @@ -519,12 +510,6 @@ private function importTNGPlac(string $gedcom): void

/**
* Extract all level 2 places from the given record and insert them into the places table
*
* @param string $xref
* @param Tree $tree
* @param string $gedrec
*
* @return void
*/
public function updatePlaces(string $xref, Tree $tree, string $gedrec): void
{
Expand All @@ -551,7 +536,7 @@ public function updatePlaces(string $xref, Tree $tree, string $gedrec): void
}

// array_unique doesn't work with arrays of arrays
$rows = array_intersect_key($rows, array_unique(array_map('serialize', $rows)));
$rows = array_intersect_key($rows, array_unique(array_map(serialize(...), $rows)));

// PDO has a limit of 65535 placeholders, and each row requires 3 placeholders.
foreach (array_chunk($rows, 20000) as $chunk) {
Expand All @@ -561,12 +546,6 @@ public function updatePlaces(string $xref, Tree $tree, string $gedrec): void

/**
* Extract all the dates from the given record and insert them into the database.
*
* @param string $xref
* @param int $ged_id
* @param string $gedrec
*
* @return void
*/
private function updateDates(string $xref, int $ged_id, string $gedrec): void
{
Expand Down Expand Up @@ -606,19 +585,13 @@ private function updateDates(string $xref, int $ged_id, string $gedrec): void
}

// array_unique doesn't work with arrays of arrays
$rows = array_intersect_key($rows, array_unique(array_map('serialize', $rows)));
$rows = array_intersect_key($rows, array_unique(array_map(serialize(...), $rows)));

DB::table('dates')->insert($rows);
DB::table('dates')->insert(array_values($rows));
}

/**
* Extract all the links from the given record and insert them into the database
*
* @param string $xref
* @param int $ged_id
* @param string $gedrec
*
* @return void
*/
private function updateLinks(string $xref, int $ged_id, string $gedrec): void
{
Expand All @@ -640,17 +613,11 @@ private function updateLinks(string $xref, int $ged_id, string $gedrec): void
];
}

DB::table('link')->insert($rows);
DB::table('link')->insert(array_values($rows));
}

/**
* Extract all the names from the given record and insert them into the database.
*
* @param string $xref
* @param int $ged_id
* @param Individual $record
*
* @return void
*/
private function updateNames(string $xref, int $ged_id, Individual $record): void
{
Expand Down Expand Up @@ -696,11 +663,6 @@ private function updateNames(string $xref, int $ged_id, Individual $record): voi

/**
* Extract inline media data, and convert to media objects.
*
* @param Tree $tree
* @param string $gedcom
*
* @return string
*/
private function convertInlineMedia(Tree $tree, string $gedcom): string
{
Expand Down Expand Up @@ -729,11 +691,6 @@ private function convertInlineMedia(Tree $tree, string $gedcom): string
*
* Legacy generates: +1 FORM / +1 FILE / +1 TITL / +1 _SCBK / +1 _PRIM / +1 _TYPE / +1 NOTE
* RootsMagic generates: +1 FILE / +1 FORM / +1 TITL
*
* @param string $gedcom
* @param Tree $tree
*
* @return string
*/
private function createMediaObject(string $gedcom, Tree $tree): string
{
Expand Down Expand Up @@ -827,19 +784,9 @@ private function createMediaObject(string $gedcom, Tree $tree): string
return $xref;
}

/**
* update a record in the database
*
* @param string $gedrec
* @param Tree $tree
* @param bool $delete
*
* @return void
* @throws GedcomErrorException
*/
public function updateRecord(string $gedrec, Tree $tree, bool $delete): void
{
if (preg_match('/^0 @(' . Gedcom::REGEX_XREF . ')@ (' . Gedcom::REGEX_TAG . ')/', $gedrec, $match)) {
if (preg_match('/^0 @(' . Gedcom::REGEX_XREF . ')@ (' . Gedcom::REGEX_TAG . ')/', $gedrec, $match) === 1) {
[, $gid, $type] = $match;
} elseif (preg_match('/^0 (HEAD)(?:\n|$)/', $gedrec, $match)) {
// The HEAD record has no XREF. Any others?
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"fisharebest/localization": "1.17.0",
"guzzlehttp/guzzle": "7.9.2",
"illuminate/database": "11.36.1",
"illuminate/support": "11.36.1",
"intervention/image": "3.10.1",
"illuminate/support": "11.37.0",
"intervention/image": "3.10.2",
"league/commonmark": "2.6.1",
"league/flysystem": "3.29.1",
"league/flysystem-path-prefixing": "3.28.0",
Expand Down
Loading

0 comments on commit dfe98cc

Please sign in to comment.