diff --git a/docs/async-api/async-api.json b/docs/async-api/async-api.json index 83c424ea..b2da154b 100644 --- a/docs/async-api/async-api.json +++ b/docs/async-api/async-api.json @@ -141,6 +141,14 @@ "crawlable": { "type": "boolean", "description": "Tells if this URL will be included as 'Allow' in Shlink's robots.txt." + }, + "forwardQuery": { + "type": "boolean", + "description": "Tells if this URL will forward the query params to the long URL when visited, as explained in [the docs](https://shlink.io/documentation/some-features/#query-params-forwarding)." + }, + "hasRedirectRules": { + "type": "boolean", + "description": "Whether this short URL has redirect rules attached to it or not. Use [this endpoint](https://api-spec.shlink.io/#/Redirect%20rules/listShortUrlRedirectRules) to get the actual list of rules." } }, "example": { @@ -164,7 +172,9 @@ }, "domain": "example.com", "title": "The title", - "crawlable": false + "crawlable": false, + "forwardQuery": false, + "hasRedirectRules": true } }, "ShortUrlMeta": { diff --git a/docs/swagger/definitions/ShortUrl.json b/docs/swagger/definitions/ShortUrl.json index 1535b65f..5de6f384 100644 --- a/docs/swagger/definitions/ShortUrl.json +++ b/docs/swagger/definitions/ShortUrl.json @@ -11,7 +11,8 @@ "domain", "title", "crawlable", - "forwardQuery" + "forwardQuery", + "hasRedirectRules" ], "properties": { "shortCode": { @@ -59,6 +60,10 @@ "forwardQuery": { "type": "boolean", "description": "Tells if this URL will forward the query params to the long URL when visited, as explained in [the docs](https://shlink.io/documentation/some-features/#query-params-forwarding)." + }, + "hasRedirectRules": { + "type": "boolean", + "description": "Whether this short URL has redirect rules attached to it or not. Use [this endpoint](https://api-spec.shlink.io/#/Redirect%20rules/listShortUrlRedirectRules) to get the actual list of rules." } } } diff --git a/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php b/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php index b159da13..2277b0e5 100644 --- a/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php +++ b/module/Core/config/entities-mappings/Shlinkio.Shlink.Core.ShortUrl.Entity.ShortUrl.php @@ -110,4 +110,9 @@ return static function (ClassMetadata $metadata, array $emConfig): void { ->columnName('forward_query') ->option('default', true) ->build(); + + $builder->createOneToMany('redirectRules', RedirectRule\Entity\ShortUrlRedirectRule::class) + ->mappedBy('shortUrl') + ->fetchExtraLazy() + ->build(); }; diff --git a/module/Core/src/ShortUrl/Entity/ShortUrl.php b/module/Core/src/ShortUrl/Entity/ShortUrl.php index e394fb5a..6f4b59c6 100644 --- a/module/Core/src/ShortUrl/Entity/ShortUrl.php +++ b/module/Core/src/ShortUrl/Entity/ShortUrl.php @@ -12,6 +12,7 @@ use Doctrine\Common\Collections\Selectable; use Shlinkio\Shlink\Common\Entity\AbstractEntity; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Exception\ShortCodeCannotBeRegeneratedException; +use Shlinkio\Shlink\Core\RedirectRule\Entity\ShortUrlRedirectRule; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlEdition; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; @@ -39,6 +40,7 @@ class ShortUrl extends AbstractEntity * @param Collection<int, Tag> $tags * @param Collection<int, Visit> & Selectable<int, Visit> $visits * @param Collection<int, ShortUrlVisitsCount> & Selectable<int, ShortUrlVisitsCount> $visitsCounts + * @param Collection<int, ShortUrlRedirectRule> $redirectRules */ private function __construct( private string $longUrl, @@ -60,6 +62,7 @@ class ShortUrl extends AbstractEntity private bool $forwardQuery = true, private ?string $importSource = null, private ?string $importOriginalShortCode = null, + private Collection $redirectRules = new ArrayCollection(), ) { } @@ -283,6 +286,7 @@ class ShortUrl extends AbstractEntity Criteria::create()->where(Criteria::expr()->eq('potentialBot', false)), )), ), + 'hasRedirectRules' => count($this->redirectRules) > 0, ]; } }