mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Ensured old visit locations are deleted when relocating a visit that has already been located
This commit is contained in:
@@ -10,7 +10,6 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Common\Util\IpAddress;
|
||||
use Shlinkio\Shlink\Core\Model\Visitor;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
||||
|
||||
class Visit extends AbstractEntity implements JsonSerializable
|
||||
@@ -60,9 +59,9 @@ class Visit extends AbstractEntity implements JsonSerializable
|
||||
return $this->shortUrl;
|
||||
}
|
||||
|
||||
public function getVisitLocation(): VisitLocationInterface
|
||||
public function getVisitLocation(): ?VisitLocationInterface
|
||||
{
|
||||
return $this->visitLocation ?? new UnknownVisitLocation();
|
||||
return $this->visitLocation;
|
||||
}
|
||||
|
||||
public function isLocatable(): bool
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user