diff --git a/src/Console/Addon.php b/src/Console/Addon.php index e4bdeb052b..277d4356f2 100644 --- a/src/Console/Addon.php +++ b/src/Console/Addon.php @@ -11,6 +11,7 @@ use Console_Table; use Friendica\App\Mode; use Friendica\Core\L10n; use Friendica\Core\Addon as AddonCore; +use Friendica\Core\Addon\AddonHelper; use Friendica\Database\Database; use Friendica\Util\Strings; use RuntimeException; @@ -34,6 +35,7 @@ class Addon extends \Asika\SimpleConsole\Console * @var Database */ private $dba; + private AddonHelper $addonHelper; protected function getHelp() { @@ -56,13 +58,14 @@ HELP; return $help; } - public function __construct(Mode $appMode, L10n $l10n, Database $dba, array $argv = null) + public function __construct(Mode $appMode, L10n $l10n, Database $dba, AddonHelper $addonHelper, array $argv = null) { parent::__construct($argv); - $this->appMode = $appMode; - $this->l10n = $l10n; - $this->dba = $dba; + $this->appMode = $appMode; + $this->l10n = $l10n; + $this->dba = $dba; + $this->addonHelper = $addonHelper; AddonCore::loadAddons(); } @@ -122,23 +125,23 @@ HELP; return false; } - foreach (AddonCore::getAvailableList() as $addon) { - $addon_name = $addon[0]; - $enabled = AddonCore::isEnabled($addon_name); + foreach ($this->addonHelper->getAvailableAddons() as $addon) { + $addonId = $addon[0]; + $enabled = $this->addonHelper->isAddonEnabled($addonId); if ($subCmd === 'all') { - $table->addRow([$addon_name, $enabled ? 'enabled' : 'disabled']); + $table->addRow([$addonId, $enabled ? 'enabled' : 'disabled']); continue; } if ($subCmd === 'enabled' && $enabled === true) { - $table->addRow([$addon_name]); + $table->addRow([$addonId]); continue; } if ($subCmd === 'disabled' && $enabled === false) { - $table->addRow([$addon_name]); + $table->addRow([$addonId]); continue; } } @@ -163,7 +166,7 @@ HELP; throw new RuntimeException($this->l10n->t('Addon not found')); } - if (AddonCore::isEnabled($addon)) { + if ($this->addonHelper->isAddonEnabled($addon)) { throw new RuntimeException($this->l10n->t('Addon already enabled')); } @@ -187,7 +190,7 @@ HELP; throw new RuntimeException($this->l10n->t('Addon not found')); } - if (!AddonCore::isEnabled($addon)) { + if (!$this->addonHelper->isAddonEnabled($addon)) { throw new RuntimeException($this->l10n->t('Addon already disabled')); } diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 4299b5ec0f..e4d8c3aa13 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -34,6 +34,8 @@ class Addon * This list is made from scanning the addon/ folder. * Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set. * + * @deprecated 2025.02 Use `Friendica\Core\Addon\AddonHelper::getAvailableAddons()` instead + * * @return array * @throws \Exception */ diff --git a/src/Core/Addon/AddonHelper.php b/src/Core/Addon/AddonHelper.php index 76d8eff75f..8b597e6472 100644 --- a/src/Core/Addon/AddonHelper.php +++ b/src/Core/Addon/AddonHelper.php @@ -14,6 +14,15 @@ namespace Friendica\Core\Addon; */ interface AddonHelper { + /** + * Returns the list of available addons with their current status and info. + * This list is made from scanning the addon/ folder. + * Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set. + * + * @return array> + */ + public function getAvailableAddons(): array; + /** * Checks if the provided addon is enabled */ diff --git a/src/Core/Addon/AddonProxy.php b/src/Core/Addon/AddonProxy.php index d53b136060..5873422313 100644 --- a/src/Core/Addon/AddonProxy.php +++ b/src/Core/Addon/AddonProxy.php @@ -18,6 +18,18 @@ use Friendica\Core\Addon; */ final class AddonProxy implements AddonHelper { + /** + * Returns the list of available addons with their current status and info. + * This list is made from scanning the addon/ folder. + * Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set. + * + * @return array> + */ + public function getAvailableAddons(): array + { + return Addon::getAvailableList(); + } + /** * Checks if the provided addon is enabled */