Replace Addon class with AddonHelper in stats modules

This commit is contained in:
Art4 2025-04-28 13:32:18 +00:00
parent ffb621f0e4
commit 2e50e93872
2 changed files with 55 additions and 23 deletions

View file

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

View file

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