fixed address import
This commit is contained in:
parent
622f53e401
commit
5d4498ac5a
|
|
@ -3127,7 +3127,12 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array
|
||||||
if (! isset($addrData['country']) || $addrData['country'] === null || $addrData['country'] === '') {
|
if (! isset($addrData['country']) || $addrData['country'] === null || $addrData['country'] === '') {
|
||||||
$addrData['country'] = 'SLO';
|
$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 = [];
|
$applyInsert = [];
|
||||||
$applyUpdate = [];
|
$applyUpdate = [];
|
||||||
foreach ($mappings as $map) {
|
foreach ($mappings as $map) {
|
||||||
|
|
@ -3176,6 +3181,11 @@ private function upsertAddress(int $personId, array $addrData, $mappings): array
|
||||||
return ['action' => 'inserted', 'address' => $created];
|
return ['action' => 'inserted', 'address' => $created];
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
// If unique constraint violation, skip instead of aborting
|
// 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')) {
|
if ($e->getCode() === '23505' || str_contains($e->getMessage(), 'unique') || str_contains($e->getMessage(), 'duplicate')) {
|
||||||
return ['action' => 'skipped', 'message' => 'Address already exists (constraint violation)'];
|
return ['action' => 'skipped', 'message' => 'Address already exists (constraint violation)'];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user