diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index 312e3917..1a81d8ed 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -11,6 +11,7 @@ use Shlinkio\Shlink\Common\Cache\RedisPublishingHelper; use Shlinkio\Shlink\Common\Mercure\MercureHubPublishingHelper; use Shlinkio\Shlink\Common\Mercure\MercureOptions; use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelper; +use Shlinkio\Shlink\Core\Matomo\MatomoOptions; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocator; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelper; @@ -188,6 +189,7 @@ return (static function (): array { MercureOptions::class, Options\WebhookOptions::class, GeoLite2Options::class, + MatomoOptions::class, ], ], diff --git a/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php b/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php index 97c0ca5d..269aed76 100644 --- a/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php +++ b/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\Helper; use Shlinkio\Shlink\Common\Mercure\MercureOptions; use Shlinkio\Shlink\Core\EventDispatcher; +use Shlinkio\Shlink\Core\Matomo\MatomoOptions; use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\Options\WebhookOptions; use Shlinkio\Shlink\EventDispatcher\Listener\EnabledListenerCheckerInterface; @@ -19,6 +20,7 @@ class EnabledListenerChecker implements EnabledListenerCheckerInterface private readonly MercureOptions $mercureOptions, private readonly WebhookOptions $webhookOptions, private readonly GeoLite2Options $geoLiteOptions, + private readonly MatomoOptions $matomoOptions, ) { } @@ -35,6 +37,7 @@ class EnabledListenerChecker implements EnabledListenerCheckerInterface EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => $this->redisPubSubEnabled, EventDispatcher\Mercure\NotifyVisitToMercure::class, EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => $this->mercureOptions->isEnabled(), + EventDispatcher\Matomo\SendVisitToMatomo::class => $this->matomoOptions->enabled, EventDispatcher\NotifyVisitToWebHooks::class => $this->webhookOptions->hasWebhooks(), EventDispatcher\UpdateGeoLiteDb::class => $this->geoLiteOptions->hasLicenseKey(), default => false, // Any unknown async listener should not be enabled by default diff --git a/module/Core/src/Matomo/MatomoOptions.php b/module/Core/src/Matomo/MatomoOptions.php index d2423684..23599321 100644 --- a/module/Core/src/Matomo/MatomoOptions.php +++ b/module/Core/src/Matomo/MatomoOptions.php @@ -7,11 +7,11 @@ namespace Shlinkio\Shlink\Core\Matomo; class MatomoOptions { public function __construct( - public readonly bool $enabled, - public readonly ?string $baseUrl, + public readonly bool $enabled = false, + public readonly ?string $baseUrl = null, /** @var numeric-string|int|null */ - private readonly string|int|null $siteId, - public readonly ?string $apiToken, + private readonly string|int|null $siteId = null, + public readonly ?string $apiToken = null, ) { } diff --git a/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php b/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php index de5017bd..44ef500c 100644 --- a/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php +++ b/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php @@ -17,6 +17,7 @@ use Shlinkio\Shlink\Core\EventDispatcher\RabbitMq\NotifyVisitToRabbitMq; use Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis; use Shlinkio\Shlink\Core\EventDispatcher\RedisPubSub\NotifyVisitToRedis; use Shlinkio\Shlink\Core\EventDispatcher\UpdateGeoLiteDb; +use Shlinkio\Shlink\Core\Matomo\MatomoOptions; use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\Options\WebhookOptions; use Shlinkio\Shlink\IpGeolocation\GeoLite2\GeoLite2Options; @@ -149,6 +150,7 @@ class EnabledListenerCheckerTest extends TestCase bool $mercureEnabled = false, bool $webhooksEnabled = false, bool $geoLiteEnabled = false, + bool $matomoEnabled = false, ): EnabledListenerChecker { return new EnabledListenerChecker( new RabbitMqOptions(enabled: $rabbitMqEnabled), @@ -156,6 +158,7 @@ class EnabledListenerCheckerTest extends TestCase new MercureOptions(publicHubUrl: $mercureEnabled ? 'the-url' : null), new WebhookOptions(['webhooks' => $webhooksEnabled ? ['foo', 'bar'] : []]), new GeoLite2Options(licenseKey: $geoLiteEnabled ? 'the-key' : null), + new MatomoOptions(enabled: $matomoEnabled), ); } }