mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
prevent loop when posting calendarrange to remote and updating remoteId
This commit is contained in:
parent
e895da31d7
commit
c892f7de7b
@ -25,6 +25,14 @@ trait RemoteCalendarTrait
|
|||||||
*/
|
*/
|
||||||
private string $remoteId = '';
|
private string $remoteId = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, the changes won't be enqueued to remote
|
||||||
|
*
|
||||||
|
* This is required to prevent update loop: a persist trigger an event creation on remote,
|
||||||
|
* which in turn change remoteId and, in turn, trigger an update change, ...
|
||||||
|
*/
|
||||||
|
public bool $preventEnqueueChanges = false;
|
||||||
|
|
||||||
public function addRemoteAttributes(array $remoteAttributes): self
|
public function addRemoteAttributes(array $remoteAttributes): self
|
||||||
{
|
{
|
||||||
$this->remoteAttributes = array_merge($this->remoteAttributes, $remoteAttributes);
|
$this->remoteAttributes = array_merge($this->remoteAttributes, $remoteAttributes);
|
||||||
|
@ -31,23 +31,27 @@ class CalendarRangeEntityListener
|
|||||||
|
|
||||||
public function postPersist(CalendarRange $calendarRange, LifecycleEventArgs $eventArgs): void
|
public function postPersist(CalendarRange $calendarRange, LifecycleEventArgs $eventArgs): void
|
||||||
{
|
{
|
||||||
$this->messageBus->dispatch(
|
if (!$calendarRange->preventEnqueueChanges) {
|
||||||
new CalendarRangeMessage(
|
$this->messageBus->dispatch(
|
||||||
$calendarRange,
|
new CalendarRangeMessage(
|
||||||
CalendarRangeMessage::CALENDAR_RANGE_PERSIST,
|
$calendarRange,
|
||||||
$this->security->getUser()
|
CalendarRangeMessage::CALENDAR_RANGE_PERSIST,
|
||||||
)
|
$this->security->getUser()
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postUpdate(CalendarRange $calendarRange, LifecycleEventArgs $eventArgs): void
|
public function postUpdate(CalendarRange $calendarRange, LifecycleEventArgs $eventArgs): void
|
||||||
{
|
{
|
||||||
$this->messageBus->dispatch(
|
if (!$calendarRange->preventEnqueueChanges) {
|
||||||
new CalendarRangeMessage(
|
$this->messageBus->dispatch(
|
||||||
$calendarRange,
|
new CalendarRangeMessage(
|
||||||
CalendarRangeMessage::CALENDAR_RANGE_UPDATE,
|
$calendarRange,
|
||||||
$this->security->getUser()
|
CalendarRangeMessage::CALENDAR_RANGE_UPDATE,
|
||||||
)
|
$this->security->getUser()
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ class CalendarRangeToRemoteHandler implements MessageHandlerInterface
|
|||||||
$range = $this->calendarRangeRepository->find($calendarRangeMessage->getCalendarRangeId());
|
$range = $this->calendarRangeRepository->find($calendarRangeMessage->getCalendarRangeId());
|
||||||
|
|
||||||
$this->remoteCalendarConnector->syncCalendarRange($range);
|
$this->remoteCalendarConnector->syncCalendarRange($range);
|
||||||
|
$range->preventEnqueueChanges = true;
|
||||||
|
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user