diff --git a/app/Services/ImportProcessor.php b/app/Services/ImportProcessor.php index 8bb6aad..f0b8305 100644 --- a/app/Services/ImportProcessor.php +++ b/app/Services/ImportProcessor.php @@ -3127,7 +3127,12 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array if (! isset($addrData['country']) || $addrData['country'] === null || $addrData['country'] === '') { $addrData['country'] = 'SLO'; } - $existing = PersonAddress::where('person_id', $personId)->where('address', $addressLine)->first(); + // Compare addresses with all spaces removed to handle whitespace variations + $addressLineNoSpaces = preg_replace('/\s+/', '', $addressLine); + $existing = PersonAddress::where('person_id', $personId) + ->whereRaw("REPLACE(address, ' ', '') = ?", [$addressLineNoSpaces]) + ->first(); + $applyInsert = []; $applyUpdate = []; foreach ($mappings as $map) { @@ -3176,6 +3181,11 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array return ['action' => 'inserted', 'address' => $created]; } catch (QueryException $e) { // If unique constraint violation, skip instead of aborting + Log::warning('Address constraint violation during import', [ + 'person_id' => $personId, + 'address' => $addressLine, + 'error' => $e->getMessage(), + ]); if ($e->getCode() === '23505' || str_contains($e->getMessage(), 'unique') || str_contains($e->getMessage(), 'duplicate')) { return ['action' => 'skipped', 'message' => 'Address already exists (constraint violation)']; }