Added forwardQuery property in short URLs, that determines if the query should be forwarded to the long URL

This commit is contained in:
Alejandro Celaya
2021-10-02 09:32:04 +02:00
parent 60c8f23a63
commit 1ed6458b39
4 changed files with 39 additions and 1 deletions

View File

@@ -43,6 +43,7 @@ class ShortUrl extends AbstractEntity
private ?string $title = null;
private bool $titleWasAutoResolved = false;
private bool $crawlable = false;
private bool $forwardQuery = true;
private function __construct()
{
@@ -207,6 +208,11 @@ class ShortUrl extends AbstractEntity
return $this->crawlable;
}
public function forwardQuery(): bool
{
return $this->forwardQuery;
}
public function update(
ShortUrlEdit $shortUrlEdit,
?ShortUrlRelationResolverInterface $relationResolver = null,

View File

@@ -21,9 +21,10 @@ class ShortUrlRedirectionBuilder implements ShortUrlRedirectionBuilderInterface
public function buildShortUrlRedirect(ShortUrl $shortUrl, array $currentQuery, ?string $extraPath = null): string
{
$uri = Uri::createFromString($shortUrl->getLongUrl());
$shouldForwardQuery = $shortUrl->forwardQuery();
return $uri
->withQuery($this->resolveQuery($uri, $currentQuery))
->withQuery($shouldForwardQuery ? $this->resolveQuery($uri, $currentQuery) : $uri->getQuery())
->withPath($this->resolvePath($uri, $extraPath))
->__toString();
}