Do not dispatch async job for matomo if disabled

This commit is contained in:
Alejandro Celaya 2023-11-15 20:02:35 +01:00
parent 9dbd15bc0c
commit f88d57b2b6
4 changed files with 12 additions and 4 deletions

View File

@ -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,
],
],

View File

@ -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

View File

@ -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,
) {
}

View File

@ -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),
);
}
}