]> git.mxchange.org Git - friendica.git/commitdiff
Add AddonHelper::getAvailableAddons() method
authorArt4 <art4@wlabs.de>
Mon, 3 Feb 2025 15:23:44 +0000 (15:23 +0000)
committerArt4 <art4@wlabs.de>
Mon, 3 Feb 2025 15:23:44 +0000 (15:23 +0000)
src/Console/Addon.php
src/Core/Addon.php
src/Core/Addon/AddonHelper.php
src/Core/Addon/AddonProxy.php

index e4bdeb052b50554f286d0cac2dbc829fdf8d9301..277d4356f2a689031e0b3600343ef468cbfdb8cc 100644 (file)
@@ -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'));
                }
 
index 4299b5ec0f63181b3315acd1025a23d8b49b755f..e4d8c3aa132c8a9cdcd445b5bb7c066a05e7511b 100644 (file)
@@ -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
         */
index 76d8eff75f8c5f0f6caf7a10c8b3128452c0f2a1..8b597e6472c0c306c892863dbf1860ae623055cf 100644 (file)
@@ -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<array<string|bool|array>>
+        */
+       public function getAvailableAddons(): array;
+
        /**
         * Checks if the provided addon is enabled
         */
index d53b136060e7cd038394d9ded42a59985cfc8495..587342231364905a9fe80fdc08bb2069e991bd50 100644 (file)
@@ -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<array<string|bool|array>>
+        */
+       public function getAvailableAddons(): array
+       {
+               return Addon::getAvailableList();
+       }
+
        /**
         * Checks if the provided addon is enabled
         */