Merge pull request #9660 from JakubOnderka/duplicate-sighting-uuid

fix: [sync] Avoid problem with duplicate sightings UUID
pull/9665/head
Jakub Onderka 2024-04-03 16:32:56 +02:00 committed by GitHub
commit 5159a72d11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 7 deletions

View File

@ -1256,6 +1256,8 @@ class Sighting extends AppModel
if (!isset($attributes[$s['attribute_uuid']])) {
continue; // attribute doesn't exists or user don't have permission to access it
}
$existingSighting[$s['uuid']] = true; // just to be sure that there are no sigthings with duplicated UUID
list($attributeId, $eventId) = $attributes[$s['attribute_uuid']];
if ($s['type'] === '2') {
@ -1271,11 +1273,8 @@ class Sighting extends AppModel
if ($user['Role']['perm_sync']) {
if (isset($s['org_id'])) {
if ($s['org_id'] != 0 && !empty($s['Organisation'])) {
if (isset($existingOrganisations[$s['Organisation']['uuid']])) {
$saveOnBehalfOf = $existingOrganisations[$s['Organisation']['uuid']];
} else {
$saveOnBehalfOf = $this->Organisation->captureOrg($s['Organisation'], $user);
}
$saveOnBehalfOf = $existingOrganisations[$s['Organisation']['uuid']] ??
$this->Organisation->captureOrg($s['Organisation'], $user);
} else {
$saveOnBehalfOf = 0;
}
@ -1297,8 +1296,8 @@ class Sighting extends AppModel
}
if ($this->saveMany($toSave)) {
$existingUuids = array_column($toSave, 'uuid');
$this->Event->publishSightingsRouter($event['Event']['id'], $user, $passAlong, $existingUuids);
$sightingsUuidsToPush = array_column($toSave, 'uuid');
$this->Event->publishSightingsRouter($event['Event']['id'], $user, $passAlong, $sightingsUuidsToPush);
return count($toSave);
}