From e908215b050aa9152803e849995e377c21d8f829 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Thu, 25 Sep 2025 17:40:39 +0200 Subject: [PATCH] use person_id from profilupdate request instead of logged in user to handle duplicates --- .../api/frontend/v1/ProfilUpdate.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index bbfed651c..6752c805a 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -813,7 +813,7 @@ class ProfilUpdate extends FHCAPI_Controller $insert_adresse_id = $insertID; $insert_adresse_id = $this->getDataOrTerminateWithError($insert_adresse_id, $this->p->t('profilUpdate', 'profilUpdate_insertAdresse_error')); if ($insert_adresse_id) { - $this->handleDupplicateZustellAdressen($requested_change['zustelladresse'], $insert_adresse_id); + $this->handleDupplicateZustellAdressen($requested_change['zustelladresse'], $insert_adresse_id, $personID); } } //! DELETE @@ -829,7 +829,7 @@ class ProfilUpdate extends FHCAPI_Controller $requested_change['updatevon'] = getAuthUID(); $update_adresse_id = $this->AdresseModel->update($adresse_id, $requested_change); $update_adresse_id = $this->getDataOrTerminateWithError($update_adresse_id, $this->p->t('profilUpdate', 'profilUpdate_updateAdresse_error')); - $this->handleDupplicateZustellAdressen($requested_change['zustelladresse'], $update_adresse_id); + $this->handleDupplicateZustellAdressen($requested_change['zustelladresse'], $update_adresse_id, $personID); } return $insertID ?? null; @@ -852,7 +852,7 @@ class ProfilUpdate extends FHCAPI_Controller $insert_kontakt_id = $insertID; $insert_kontakt_id = $this->getDataOrTerminateWithError($insert_kontakt_id, $this->p->t('profilUpdate', 'profilUpdate_insertKontakt_error')); if ($insert_kontakt_id) { - $this->handleDupplicateZustellKontakte($requested_change['zustellung'], $insert_kontakt_id); + $this->handleDupplicateZustellKontakte($requested_change['zustellung'], $insert_kontakt_id, $personID); } } //! DELETE @@ -869,18 +869,18 @@ class ProfilUpdate extends FHCAPI_Controller $update_kontakt_id = $this->KontaktModel->update($kontakt_id, $requested_change); $update_kontakt_id = $this->getDataOrTerminateWithError($update_kontakt_id, $this->p->t('profilUpdate', 'profilUpdate_updateKontakt_error')); if ($update_kontakt_id) { - $this->handleDupplicateZustellKontakte($requested_change['zustellung'], $update_kontakt_id); + $this->handleDupplicateZustellKontakte($requested_change['zustellung'], $update_kontakt_id, $personID); } } return isset($insertID) ? $insertID : null; } - private function handleDupplicateZustellAdressen($zustellung, $adresse_id) + private function handleDupplicateZustellAdressen($zustellung, $adresse_id, $person_id) { if ($zustellung) { $this->PersonModel->addSelect("public.tbl_adresse.adresse_id"); $this->PersonModel->addJoin("public.tbl_adresse", "public.tbl_adresse.person_id = public.tbl_person.person_id"); - $zustellAdressenArray = $this->PersonModel->loadWhere(["public.tbl_person.person_id" => $this->pid, "zustelladresse" => TRUE]); + $zustellAdressenArray = $this->PersonModel->loadWhere(["public.tbl_person.person_id" => $person_id, "zustelladresse" => TRUE]); if (isError($zustellAdressenArray)) { $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loadingZustellAdressen_error')); } @@ -893,6 +893,8 @@ class ProfilUpdate extends FHCAPI_Controller return $adresse->adresse_id != $adresse_id; }); + $this->addMeta('bhzustelladressen', $zustellAdressenArray); + // remove the zustelladresse from all other zustelladressen foreach ($zustellAdressenArray as $adresse) { $this->AdresseModel->update($adresse->adresse_id, ["zustelladresse" => FALSE]); @@ -902,12 +904,12 @@ class ProfilUpdate extends FHCAPI_Controller } } - private function handleDupplicateZustellKontakte($zustellung, $kontakt_id) + private function handleDupplicateZustellKontakte($zustellung, $kontakt_id, $person_id) { if ($zustellung) { $this->PersonModel->addSelect("public.tbl_kontakt.kontakt_id"); $this->PersonModel->addJoin("public.tbl_kontakt", "public.tbl_kontakt.person_id = public.tbl_person.person_id"); - $zustellKontakteArray = $this->PersonModel->loadWhere(["public.tbl_person.person_id" => $this->pid, "zustellung" => TRUE]); + $zustellKontakteArray = $this->PersonModel->loadWhere(["public.tbl_person.person_id" => $person_id, "zustellung" => TRUE]); if (!isSuccess($zustellKontakteArray)) { return error($this->p->t('profilUpdate', 'profilUpdate_loadingZustellkontakte_error')); }