use person_id from profilupdate request instead of logged in user to handle duplicates

This commit is contained in:
Harald Bamberger
2025-09-25 17:40:39 +02:00
parent 6047b19f47
commit e908215b05
@@ -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'));
}