From 23cffce861fbd418c9ecaae30c0b5b5afda54885 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 7 Feb 2021 11:02:50 +0100 Subject: [PATCH] Updated Visit entity so that the short URL is nullable --- module/Core/src/Entity/Visit.php | 11 ++--------- .../src/EventDispatcher/NotifyVisitToWebHooks.php | 4 ++-- module/Core/src/Mercure/MercureUpdatesGenerator.php | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/module/Core/src/Entity/Visit.php b/module/Core/src/Entity/Visit.php index 7e6ed060..c2b79a04 100644 --- a/module/Core/src/Entity/Visit.php +++ b/module/Core/src/Entity/Visit.php @@ -18,7 +18,7 @@ class Visit extends AbstractEntity implements JsonSerializable private Chronos $date; private ?string $remoteAddr = null; private string $userAgent; - private ShortUrl $shortUrl; + private ?ShortUrl $shortUrl; private ?VisitLocation $visitLocation = null; public function __construct(ShortUrl $shortUrl, Visitor $visitor, bool $anonymize = true, ?Chronos $date = null) @@ -54,7 +54,7 @@ class Visit extends AbstractEntity implements JsonSerializable return ! empty($this->remoteAddr); } - public function getShortUrl(): ShortUrl + public function getShortUrl(): ?ShortUrl { return $this->shortUrl; } @@ -75,13 +75,6 @@ class Visit extends AbstractEntity implements JsonSerializable return $this; } - /** - * Specify data which should be serialized to JSON - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return array data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ public function jsonSerialize(): array { return [ diff --git a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php index d3b27602..b236a1c1 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php @@ -10,6 +10,7 @@ use Fig\Http\Message\RequestMethodInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\PromiseInterface; +use GuzzleHttp\Promise\Utils; use GuzzleHttp\RequestOptions; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; @@ -20,7 +21,6 @@ use Throwable; use function Functional\map; use function Functional\partial_left; -use function GuzzleHttp\Promise\settle; class NotifyVisitToWebHooks { @@ -69,7 +69,7 @@ class NotifyVisitToWebHooks $requestPromises = $this->performRequests($requestOptions, $visitId); // Wait for all the promises to finish, ignoring rejections, as in those cases we only want to log the error. - settle($requestPromises)->wait(); + Utils::settle($requestPromises)->wait(); } private function buildRequestOptions(Visit $visit): array diff --git a/module/Core/src/Mercure/MercureUpdatesGenerator.php b/module/Core/src/Mercure/MercureUpdatesGenerator.php index bd00e836..9a0a28f3 100644 --- a/module/Core/src/Mercure/MercureUpdatesGenerator.php +++ b/module/Core/src/Mercure/MercureUpdatesGenerator.php @@ -38,7 +38,7 @@ final class MercureUpdatesGenerator implements MercureUpdatesGeneratorInterface $topic = sprintf('%s/%s', self::NEW_VISIT_TOPIC, $shortUrl->getShortCode()); return new Update($topic, $this->serialize([ - 'shortUrl' => $this->transformer->transform($visit->getShortUrl()), + 'shortUrl' => $this->transformer->transform($shortUrl), 'visit' => $visit, ])); }