Ensured old visit locations are deleted when relocating a visit that has already been located

This commit is contained in:
Alejandro Celaya
2020-03-28 09:27:45 +01:00
parent fb8ab0b5fe
commit 55778eb810
4 changed files with 12 additions and 6 deletions

View File

@@ -79,9 +79,16 @@ class VisitLocator implements VisitLocatorInterface
private function locateVisit(Visit $visit, VisitLocation $location, VisitGeolocationHelperInterface $helper): void
{
$prevLocation = $visit->getVisitLocation();
$visit->locate($location);
$this->em->persist($visit);
// In order to avoid leaving orphan locations, remove the previous one
if ($prevLocation !== null) {
$this->em->remove($prevLocation);
}
$helper->onVisitLocated($location, $visit);
}
}