Do not dispatch PersonMoveEvent if moving to a position not sharing

household
This commit is contained in:
2022-03-30 11:57:43 +02:00
parent df24d085ca
commit e433b6a42b
2 changed files with 28 additions and 5 deletions

View File

@@ -61,8 +61,6 @@ class MembersEditor
throw new LogicException('You must define a household first');
}
$event = new PersonAddressMoveEvent($person);
$membership = (new HouseholdMember())
->setStartDate($date)
->setPerson($person)
@@ -70,9 +68,13 @@ class MembersEditor
->setHolder($holder)
->setComment($comment);
$this->household->addMember($membership);
$event->setNextMembership($membership);
if ($position->getShareHousehold()) {
// launch event only if moving to a "share household" position
$event = new PersonAddressMoveEvent($person);
$event->setNextMembership($membership);
$this->events[] = $event;
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
if ($participation === $membership) {
continue;
@@ -108,7 +110,6 @@ class MembersEditor
$this->membershipsAffected[] = $membership;
$this->persistables[] = $membership;
$this->events[] = $event;
return $this;
}