mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Create constant representing default domain identifier
This commit is contained in:
@@ -11,6 +11,8 @@ use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
||||
|
||||
class Domain extends AbstractEntity implements JsonSerializable, NotFoundRedirectConfigInterface
|
||||
{
|
||||
public const DEFAULT_AUTHORITY = 'DEFAULT';
|
||||
|
||||
private function __construct(
|
||||
public readonly string $authority,
|
||||
private ?string $baseUrlRedirect = null,
|
||||
|
||||
@@ -25,6 +25,7 @@ class ShortUrlsCountFiltering
|
||||
public readonly bool $excludePastValidUntil = false,
|
||||
public readonly ?ApiKey $apiKey = null,
|
||||
?string $defaultDomain = null,
|
||||
public readonly ?string $domain = null,
|
||||
) {
|
||||
$this->searchIncludesDefaultDomain = !empty($searchTerm) && !empty($defaultDomain) && str_contains(
|
||||
strtolower($defaultDomain),
|
||||
|
||||
@@ -104,14 +104,13 @@ class ShortUrlListRepository extends EntitySpecificationRepository implements Sh
|
||||
|
||||
$searchTerm = $filtering->searchTerm;
|
||||
$tags = $filtering->tags;
|
||||
// Apply search term to every searchable field if not empty
|
||||
if (! empty($searchTerm)) {
|
||||
// Left join with tags only if no tags were provided. In case of tags, an inner join will be done later
|
||||
if (empty($tags)) {
|
||||
$qb->leftJoin('s.tags', 't');
|
||||
}
|
||||
|
||||
// Apply general search conditions
|
||||
// Apply search term to every "searchable" field
|
||||
$conditions = [
|
||||
$qb->expr()->like('s.longUrl', ':searchPattern'),
|
||||
$qb->expr()->like('s.shortCode', ':searchPattern'),
|
||||
@@ -142,6 +141,9 @@ class ShortUrlListRepository extends EntitySpecificationRepository implements Sh
|
||||
: $this->joinAllTags($qb, $tags);
|
||||
}
|
||||
|
||||
if ($filtering->domain !== null) {
|
||||
}
|
||||
|
||||
if ($filtering->excludeMaxVisitsReached) {
|
||||
$qb->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->isNull('s.maxVisits'),
|
||||
|
||||
@@ -8,6 +8,7 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepositoryInterface;
|
||||
@@ -124,7 +125,7 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
|
||||
$qb->from(Visit::class, 'v')
|
||||
->join('v.shortUrl', 's');
|
||||
|
||||
if ($domain === 'DEFAULT') {
|
||||
if ($domain === Domain::DEFAULT_AUTHORITY) {
|
||||
$qb->where($qb->expr()->isNull('s.domain'));
|
||||
} else {
|
||||
$qb->join('s.domain', 'd')
|
||||
|
||||
@@ -109,7 +109,7 @@ readonly class VisitsStatsHelper implements VisitsStatsHelperInterface
|
||||
{
|
||||
/** @var DomainRepository $domainRepo */
|
||||
$domainRepo = $this->em->getRepository(Domain::class);
|
||||
if ($domain !== 'DEFAULT' && ! $domainRepo->domainExists($domain, $apiKey)) {
|
||||
if ($domain !== Domain::DEFAULT_AUTHORITY && ! $domainRepo->domainExists($domain, $apiKey)) {
|
||||
throw DomainNotFoundException::fromAuthority($domain);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user