From fa5ebb16770e2700c005e2c17a8745a035e6eda4 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 27 Jul 2022 16:47:21 +0200 Subject: [PATCH] Integrated PublishUpdatesGenerator in NotifyNewShortUrlToRedis listener --- module/Core/config/event_dispatcher.config.php | 2 +- .../RedisPubSub/NotifyNewShortUrlToRedis.php | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index 4a9dc32d..441a95cf 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -128,9 +128,9 @@ return [ ], EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => [ RedisPublishingHelper::class, + EventDispatcher\PublishingUpdatesGenerator::class, 'em', 'Logger_Shlink', - ShortUrl\Transformer\ShortUrlDataTransformer::class, 'config.redis.pub_sub_enabled', ], EventDispatcher\UpdateGeoLiteDb::class => [GeolocationDbUpdater::class, 'Logger_Shlink'], diff --git a/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php b/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php index 638aa88a..4a56858e 100644 --- a/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php +++ b/module/Core/src/EventDispatcher/RedisPubSub/NotifyNewShortUrlToRedis.php @@ -6,21 +6,19 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; -use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; -use Shlinkio\Shlink\Common\UpdatePublishing\Update; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated; -use Shlinkio\Shlink\Core\EventDispatcher\Topic; +use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Throwable; class NotifyNewShortUrlToRedis { public function __construct( private readonly PublishingHelperInterface $redisHelper, + private readonly PublishingUpdatesGeneratorInterface $updatesGenerator, private readonly EntityManagerInterface $em, private readonly LoggerInterface $logger, - private readonly DataTransformerInterface $shortUrlTransformer, private readonly bool $enabled, ) { } @@ -43,10 +41,7 @@ class NotifyNewShortUrlToRedis } try { - $this->redisHelper->publishUpdate(Update::forTopicAndPayload( - Topic::NEW_SHORT_URL->value, - ['shortUrl' => $this->shortUrlTransformer->transform($shortUrl)], - )); + $this->redisHelper->publishUpdate($this->updatesGenerator->newShortUrlUpdate($shortUrl)); } catch (Throwable $e) { $this->logger->debug('Error while trying to notify Redis pub/sub with new short URL. {e}', ['e' => $e]); }