Add AddonHelper::getAvailableAddons() method

This commit is contained in:
Art4 2025-02-03 15:23:44 +00:00
parent 4ea648475f
commit b84eb33ae2
4 changed files with 38 additions and 12 deletions

View file

@ -11,6 +11,7 @@ use Console_Table;
use Friendica\App\Mode; use Friendica\App\Mode;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Addon as AddonCore; use Friendica\Core\Addon as AddonCore;
use Friendica\Core\Addon\AddonHelper;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use RuntimeException; use RuntimeException;
@ -34,6 +35,7 @@ class Addon extends \Asika\SimpleConsole\Console
* @var Database * @var Database
*/ */
private $dba; private $dba;
private AddonHelper $addonHelper;
protected function getHelp() protected function getHelp()
{ {
@ -56,13 +58,14 @@ HELP;
return $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); parent::__construct($argv);
$this->appMode = $appMode; $this->appMode = $appMode;
$this->l10n = $l10n; $this->l10n = $l10n;
$this->dba = $dba; $this->dba = $dba;
$this->addonHelper = $addonHelper;
AddonCore::loadAddons(); AddonCore::loadAddons();
} }
@ -122,23 +125,23 @@ HELP;
return false; return false;
} }
foreach (AddonCore::getAvailableList() as $addon) { foreach ($this->addonHelper->getAvailableAddons() as $addon) {
$addon_name = $addon[0]; $addonId = $addon[0];
$enabled = AddonCore::isEnabled($addon_name); $enabled = $this->addonHelper->isAddonEnabled($addonId);
if ($subCmd === 'all') { if ($subCmd === 'all') {
$table->addRow([$addon_name, $enabled ? 'enabled' : 'disabled']); $table->addRow([$addonId, $enabled ? 'enabled' : 'disabled']);
continue; continue;
} }
if ($subCmd === 'enabled' && $enabled === true) { if ($subCmd === 'enabled' && $enabled === true) {
$table->addRow([$addon_name]); $table->addRow([$addonId]);
continue; continue;
} }
if ($subCmd === 'disabled' && $enabled === false) { if ($subCmd === 'disabled' && $enabled === false) {
$table->addRow([$addon_name]); $table->addRow([$addonId]);
continue; continue;
} }
} }
@ -163,7 +166,7 @@ HELP;
throw new RuntimeException($this->l10n->t('Addon not found')); 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')); throw new RuntimeException($this->l10n->t('Addon already enabled'));
} }
@ -187,7 +190,7 @@ HELP;
throw new RuntimeException($this->l10n->t('Addon not found')); 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')); throw new RuntimeException($this->l10n->t('Addon already disabled'));
} }

View file

@ -34,6 +34,8 @@ class Addon
* This list is made from scanning the addon/ folder. * 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. * 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 * @return array
* @throws \Exception * @throws \Exception
*/ */

View file

@ -14,6 +14,15 @@ namespace Friendica\Core\Addon;
*/ */
interface AddonHelper 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<array<string|bool|array>>
*/
public function getAvailableAddons(): array;
/** /**
* Checks if the provided addon is enabled * Checks if the provided addon is enabled
*/ */

View file

@ -18,6 +18,18 @@ use Friendica\Core\Addon;
*/ */
final class AddonProxy implements AddonHelper 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<array<string|bool|array>>
*/
public function getAvailableAddons(): array
{
return Addon::getAvailableList();
}
/** /**
* Checks if the provided addon is enabled * Checks if the provided addon is enabled
*/ */