This commit is contained in:
Simon Pocrnjič 2025-12-17 22:14:43 +01:00
parent 2140181a76
commit 94ad0c0772

View File

@ -3118,9 +3118,10 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array
if (mb_strlen($addressLine) < 3) {
return ['action' => 'skipped', 'message' => 'Invalid address value'];
}
// Allow letters (incl. diacritics), numbers, and common separators
if (! preg_match('/^[\\p{L}0-9\\s\\.,\\-\\/\\#\\\'"\\(\\)&]+$/u', $addressLine)) {
return ['action' => 'skipped', 'message' => 'Invalid address value'];
// If identical address already exists anywhere, skip to avoid constraint violation
$existingAny = PersonAddress::where('address', $addressLine)->first();
if ($existingAny && $existingAny->person_id !== $personId) {
return ['action' => 'skipped', 'message' => 'Address already exists for another person'];
}
// Default country SLO if not provided
if (! isset($addrData['country']) || $addrData['country'] === null || $addrData['country'] === '') {