mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Ensured domain is taken into account when checking if a slug is in use
This commit is contained in:
@@ -138,4 +138,25 @@ DQL;
|
||||
$result = $query->getOneOrNullResult();
|
||||
return $result === null || $result->maxVisitsReached() ? null : $result;
|
||||
}
|
||||
|
||||
public function slugIsInUse(string $slug, ?string $domain = null): bool
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->select('COUNT(DISTINCT s.id)')
|
||||
->from(ShortUrl::class, 's')
|
||||
->where($qb->expr()->isNotNull('s.shortCode'))
|
||||
->andWhere($qb->expr()->eq('s.shortCode', ':slug'))
|
||||
->setParameter('slug', $slug);
|
||||
|
||||
if ($domain !== null) {
|
||||
$qb->join('s.domain', 'd')
|
||||
->andWhere($qb->expr()->eq('d.authority', ':authority'))
|
||||
->setParameter('authority', $domain);
|
||||
} else {
|
||||
$qb->andWhere($qb->expr()->isNull('s.domain'));
|
||||
}
|
||||
|
||||
$result = (int) $qb->getQuery()->getSingleScalarResult();
|
||||
return $result > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,6 @@ interface ShortUrlRepositoryInterface extends ObjectRepository
|
||||
public function countList(?string $searchTerm = null, array $tags = []): int;
|
||||
|
||||
public function findOneByShortCode(string $shortCode): ?ShortUrl;
|
||||
|
||||
public function slugIsInUse(string $slug, ?string $domain): bool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user