Create DB logic to delete orphan visits

This commit is contained in:
Alejandro Celaya
2023-05-18 08:57:24 +02:00
parent b51c149c30
commit a4d8ebdfc9
5 changed files with 32 additions and 4 deletions

View File

@@ -19,4 +19,13 @@ class VisitDeleterRepository extends EntitySpecificationRepository implements Vi
return $qb->getQuery()->execute();
}
public function deleteOrphanVisits(): int
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->delete(Visit::class, 'v')
->where($qb->expr()->isNull('v.shortUrl'));
return $qb->getQuery()->execute();
}
}

View File

@@ -9,4 +9,6 @@ use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
interface VisitDeleterRepositoryInterface
{
public function deleteShortUrlVisits(ShortUrl $shortUrl): int;
public function deleteOrphanVisits(): int;
}