From b4d137375a9b2e9201d2cd9c8eaf345383faa54f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 7 Apr 2021 11:35:02 +0200 Subject: [PATCH] Flipped events triggered when locating a visit, so that geolocation is done synchronously --- .../GeolocationDbUpdateFailedException.php | 5 +++++ .../Core/config/event_dispatcher.config.php | 20 +++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php b/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php index f663fd8f..07d66855 100644 --- a/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php +++ b/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php @@ -13,6 +13,11 @@ class GeolocationDbUpdateFailedException extends RuntimeException implements Exc { private bool $olderDbExists; + private function __construct(string $message, int $code = 0, ?Throwable $previous = null) + { + parent::__construct($message, $code, $previous); + } + public static function withOlderDb(?Throwable $prev = null): self { $e = new self( diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index 5e1a6c9f..37b1d59d 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -6,7 +6,7 @@ namespace Shlinkio\Shlink\Core; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Psr\EventDispatcher\EventDispatcherInterface; -use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater; +use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdater; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; use Symfony\Component\Mercure\Hub; @@ -14,14 +14,15 @@ return [ 'events' => [ 'regular' => [ - EventDispatcher\Event\VisitLocated::class => [ - EventDispatcher\NotifyVisitToMercure::class, - EventDispatcher\NotifyVisitToWebHooks::class, + EventDispatcher\Event\UrlVisited::class => [ + EventDispatcher\LocateVisit::class, ], ], 'async' => [ - EventDispatcher\Event\UrlVisited::class => [ - EventDispatcher\LocateVisit::class, + EventDispatcher\Event\VisitLocated::class => [ + EventDispatcher\NotifyVisitToMercure::class, + EventDispatcher\NotifyVisitToWebHooks::class, +// EventDispatcher\UpdateGeoliteDb::class, ], ], ], @@ -34,7 +35,10 @@ return [ ], 'delegators' => [ - EventDispatcher\LocateVisit::class => [ + EventDispatcher\NotifyVisitToMercure::class => [ + EventDispatcher\CloseDbConnectionEventListenerDelegator::class, + ], + EventDispatcher\NotifyVisitToWebHooks::class => [ EventDispatcher\CloseDbConnectionEventListenerDelegator::class, ], ], @@ -45,7 +49,7 @@ return [ IpLocationResolverInterface::class, 'em', 'Logger_Shlink', - GeolocationDbUpdater::class, + DbUpdater::class, EventDispatcherInterface::class, ], EventDispatcher\NotifyVisitToWebHooks::class => [