From 2e50e9387290c83d95e8f73a370286d6d207a8c9 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 28 Apr 2025 13:32:18 +0000 Subject: [PATCH] Replace Addon class with AddonHelper in stats modules --- src/Module/Statistics.php | 46 ++++++++++++++++++++++++++------------- src/Module/Stats.php | 32 ++++++++++++++++++++------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 6a5996dac9..4a35d55d12 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -8,8 +8,10 @@ namespace Friendica\Module; use Friendica\App; +use Friendica\App\Arguments; +use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\Addon; +use Friendica\Core\Addon\AddonHelper; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\L10n; @@ -23,13 +25,27 @@ class Statistics extends BaseModule protected $config; /** @var IManageKeyValuePairs */ protected $keyValue; + private AddonHelper $addonHelper; - public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Response $response, array $server, array $parameters = []) - { + public function __construct( + L10n $l10n, + BaseURL $baseUrl, + Arguments $args, + LoggerInterface $logger, + Profiler $profiler, + IManageConfigValues $config, + IManageKeyValuePairs $keyValue, + AddonHelper $addonHelper, + Response $response, + array $server, + array $parameters = [] + ) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); - $this->config = $config; - $this->keyValue = $keyValue; + $this->config = $config; + $this->keyValue = $keyValue; + $this->addonHelper = $addonHelper; + if (!$this->config->get("system", "nodeinfo")) { throw new NotFoundException(); } @@ -43,16 +59,16 @@ class Statistics extends BaseModule /// @todo mark the "service" addons and load them dynamically here $services = [ - 'appnet' => Addon::isEnabled('appnet'), - 'bluesky' => Addon::isEnabled('bluesky'), - 'dreamwidth' => Addon::isEnabled('dreamwidth'), - 'gnusocial' => Addon::isEnabled('gnusocial'), - 'libertree' => Addon::isEnabled('libertree'), - 'livejournal' => Addon::isEnabled('livejournal'), - 'pumpio' => Addon::isEnabled('pumpio'), - 'twitter' => Addon::isEnabled('twitter'), - 'tumblr' => Addon::isEnabled('tumblr'), - 'wordpress' => Addon::isEnabled('wordpress'), + 'appnet' => $this->addonHelper->isAddonEnabled('appnet'), + 'bluesky' => $this->addonHelper->isAddonEnabled('bluesky'), + 'dreamwidth' => $this->addonHelper->isAddonEnabled('dreamwidth'), + 'gnusocial' => $this->addonHelper->isAddonEnabled('gnusocial'), + 'libertree' => $this->addonHelper->isAddonEnabled('libertree'), + 'livejournal' => $this->addonHelper->isAddonEnabled('livejournal'), + 'pumpio' => $this->addonHelper->isAddonEnabled('pumpio'), + 'twitter' => $this->addonHelper->isAddonEnabled('twitter'), + 'tumblr' => $this->addonHelper->isAddonEnabled('tumblr'), + 'wordpress' => $this->addonHelper->isAddonEnabled('wordpress'), ]; $statistics = array_merge([ diff --git a/src/Module/Stats.php b/src/Module/Stats.php index 4bc9d95711..e59696a889 100644 --- a/src/Module/Stats.php +++ b/src/Module/Stats.php @@ -8,8 +8,10 @@ namespace Friendica\Module; use Friendica\App; +use Friendica\App\Arguments; +use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\Addon; +use Friendica\Core\Addon\AddonHelper; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\L10n; @@ -40,14 +42,28 @@ class Stats extends BaseModule protected $logger; /** @var IManageKeyValuePairs */ protected $keyValue; + private AddonHelper $addonHelper; - public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Database $dba, Response $response, array $server, array $parameters = []) - { + public function __construct( + L10n $l10n, + BaseURL $baseUrl, + Arguments $args, + LoggerInterface $logger, + Profiler $profiler, + IManageConfigValues $config, + IManageKeyValuePairs $keyValue, + Database $dba, + AddonHelper $addonHelper, + Response $response, + array $server, + array $parameters = [] + ) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); - $this->config = $config; - $this->keyValue = $keyValue; - $this->dba = $dba; + $this->config = $config; + $this->keyValue = $keyValue; + $this->dba = $dba; + $this->addonHelper = $addonHelper; } protected function content(array $request = []): string @@ -164,11 +180,11 @@ class Stats extends BaseModule ], ]; - if (Addon::isEnabled('bluesky')) { + if ($this->addonHelper->isAddonEnabled('bluesky')) { $statistics['packets']['inbound'][Protocol::BLUESKY] = intval($this->keyValue->get('stats_packets_inbound_' . Protocol::BLUESKY) ?? 0); $statistics['packets']['outbound'][Protocol::BLUESKY] = intval($this->keyValue->get('stats_packets_outbound_' . Protocol::BLUESKY) ?? 0); } - if (Addon::isEnabled('tumblr')) { + if ($this->addonHelper->isAddonEnabled('tumblr')) { $statistics['packets']['inbound'][Protocol::TUMBLR] = intval($this->keyValue->get('stats_packets_inbound_' . Protocol::TUMBLR) ?? 0); $statistics['packets']['outbound'][Protocol::TUMBLR] = intval($this->keyValue->get('stats_packets_outbound_' . Protocol::TUMBLR) ?? 0); }