mirror of
https://github.com/friendica/friendica
synced 2025-02-19 06:46:47 +00:00
Add AddonHelper::getAvailableAddons() method
This commit is contained in:
parent
4ea648475f
commit
b84eb33ae2
4 changed files with 38 additions and 12 deletions
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue