Ensured visits tracking is run transactionally together with the event dispatched afterwards

This commit is contained in:
Alejandro Celaya
2021-04-07 11:33:23 +02:00
parent 3a6a1f25a7
commit 0621ae7735
2 changed files with 16 additions and 5 deletions

View File

@@ -65,9 +65,11 @@ class VisitsTracker implements VisitsTrackerInterface
private function trackVisit(Visit $visit, Visitor $visitor): void
{
$this->em->persist($visit);
$this->em->flush();
$this->em->transactional(function () use ($visit, $visitor): void {
$this->em->persist($visit);
$this->em->flush();
$this->eventDispatcher->dispatch(new UrlVisited($visit->getId(), $visitor->getRemoteAddress()));
$this->eventDispatcher->dispatch(new UrlVisited($visit->getId(), $visitor->getRemoteAddress()));
});
}
}