do not launch PersonMoveEvent when moving to the same household

This commit is contained in:
2022-03-30 16:42:57 +02:00
parent dae9d48574
commit 36b1f05524
3 changed files with 84 additions and 4 deletions

View File

@@ -70,10 +70,12 @@ class MembersEditor
$this->household->addMember($membership);
if ($position->getShareHousehold()) {
// launch event only if moving to a "share household" position
// launch event only if moving to a "share household" position,
// and if the destination household is different than the previous one
$event = new PersonAddressMoveEvent($person);
$event->setNextMembership($membership);
$this->events[] = $event;
$counter = 0;
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
if ($participation === $membership) {
@@ -84,14 +86,25 @@ class MembersEditor
continue;
}
++$counter;
if ($participation->getEndDate() === null || $participation->getEndDate() > $date) {
$event->setPreviousMembership($participation);
$participation->setEndDate($date);
$this->membershipsAffected[] = $participation;
$this->oldMembershipsHashes[] = spl_object_hash($participation);
if ($participation->getHousehold() !== $this->household) {
$event->setPreviousMembership($participation);
$this->events[] = $event;
}
}
}
// send also the event if there was no participation before
if (0 === $counter) {
$this->events[] = $event;
}
foreach ($person->getHouseholdParticipationsNotShareHousehold() as $participation) {
if ($participation->getHousehold() === $this->household
&& $participation->getEndDate() === null || $participation->getEndDate() > $membership->getStartDate()