mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Fixed error when editing domain redirects for a new domain
This commit is contained in:
parent
9f25979b4c
commit
7b43403b1c
@ -23,8 +23,14 @@ class DomainRepository extends EntitySpecificationRepository implements DomainRe
|
||||
*/
|
||||
public function findDomainsWithout(?string $excludedAuthority, ?ApiKey $apiKey = null): array
|
||||
{
|
||||
$qb = $this->createPublicDomainsQueryBuilder();
|
||||
$qb->orderBy('d.authority', 'ASC');
|
||||
$qb = $this->createQueryBuilder('d');
|
||||
$qb->leftJoin(ShortUrl::class, 's', Join::WITH, 's.domain = d')
|
||||
->groupBy('d')
|
||||
->orderBy('d.authority', 'ASC')
|
||||
->having($qb->expr()->gt('COUNT(s.id)', '0'))
|
||||
->orHaving($qb->expr()->isNotNull('d.baseUrlRedirect'))
|
||||
->orHaving($qb->expr()->isNotNull('d.regular404Redirect'))
|
||||
->orHaving($qb->expr()->isNotNull('d.invalidShortUrlRedirect'));
|
||||
|
||||
$specs = $this->determineExtraSpecs($excludedAuthority, $apiKey);
|
||||
foreach ($specs as [$alias, $spec]) {
|
||||
@ -36,8 +42,9 @@ class DomainRepository extends EntitySpecificationRepository implements DomainRe
|
||||
|
||||
public function findOneByAuthority(string $authority, ?ApiKey $apiKey = null): ?Domain
|
||||
{
|
||||
$qb = $this->createPublicDomainsQueryBuilder();
|
||||
$qb->where($qb->expr()->eq('d.authority', ':authority'))
|
||||
$qb = $this->createQueryBuilder('d');
|
||||
$qb->leftJoin(ShortUrl::class, 's', Join::WITH, 's.domain = d')
|
||||
->where($qb->expr()->eq('d.authority', ':authority'))
|
||||
->setParameter('authority', $authority)
|
||||
->setMaxResults(1);
|
||||
|
||||
@ -49,19 +56,6 @@ class DomainRepository extends EntitySpecificationRepository implements DomainRe
|
||||
return $qb->getQuery()->getOneOrNullResult();
|
||||
}
|
||||
|
||||
private function createPublicDomainsQueryBuilder(): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('d');
|
||||
$qb->leftJoin(ShortUrl::class, 's', Join::WITH, 's.domain = d')
|
||||
->groupBy('d')
|
||||
->having($qb->expr()->gt('COUNT(s.id)', '0'))
|
||||
->orHaving($qb->expr()->isNotNull('d.baseUrlRedirect'))
|
||||
->orHaving($qb->expr()->isNotNull('d.regular404Redirect'))
|
||||
->orHaving($qb->expr()->isNotNull('d.invalidShortUrlRedirect'));
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
private function determineExtraSpecs(?string $excludedAuthority, ?ApiKey $apiKey): iterable
|
||||
{
|
||||
if ($excludedAuthority !== null) {
|
||||
|
@ -74,7 +74,7 @@ class DomainRepositoryTest extends DatabaseTestCase
|
||||
self::assertEquals($barDomain, $this->repo->findOneByAuthority('bar.com'));
|
||||
self::assertEquals($detachedWithRedirects, $this->repo->findOneByAuthority('detached-with-redirects.com'));
|
||||
self::assertNull($this->repo->findOneByAuthority('does-not-exist.com'));
|
||||
self::assertNull($this->repo->findOneByAuthority('detached.com'));
|
||||
self::assertEquals($detachedDomain, $this->repo->findOneByAuthority('detached.com'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -23,7 +23,7 @@ class DomainRedirectsAction extends AbstractRestAction
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
// TODO Do not allow to set redirects for default domain
|
||||
// TODO Do not allow to set redirects for default domain. Or do allow. Check if there could be any issue
|
||||
|
||||
/** @var array $body */
|
||||
$body = $request->getParsedBody();
|
||||
|
Loading…
Reference in New Issue
Block a user