mirror of
https://github.com/friendica/friendica
synced 2025-04-28 03:50:17 +00:00
Use addons config entries instead of the addon table
This commit is contained in:
parent
cd11088cc4
commit
13b234d279
7 changed files with 294 additions and 39 deletions
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -85,15 +84,18 @@ class Addon
|
|||
public static function getAdminList()
|
||||
{
|
||||
$addons_admin = [];
|
||||
$addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]);
|
||||
while ($addon = DBA::fetch($addonsAdminStmt)) {
|
||||
$addons_admin[$addon['name']] = [
|
||||
'url' => 'admin/addons/' . $addon['name'],
|
||||
'name' => $addon['name'],
|
||||
$addons = DI::config()->get('addons');
|
||||
foreach ($addons as $name => $data) {
|
||||
if (empty($data['admin'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addons_admin[$name] = [
|
||||
'url' => 'admin/addons/' . $name,
|
||||
'name' => $name,
|
||||
'class' => 'addon'
|
||||
];
|
||||
}
|
||||
DBA::close($addonsAdminStmt);
|
||||
|
||||
return $addons_admin;
|
||||
}
|
||||
|
@ -113,8 +115,7 @@ class Addon
|
|||
*/
|
||||
public static function loadAddons()
|
||||
{
|
||||
$installed_addons = DBA::selectToArray('addon', ['name'], ['installed' => true]);
|
||||
self::$addons = array_column($installed_addons, 'name');
|
||||
self::$addons = array_keys(DI::config()->get('addons') ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +130,7 @@ class Addon
|
|||
$addon = Strings::sanitizeFilePathItem($addon);
|
||||
|
||||
Logger::debug("Addon {addon}: {action}", ['action' => 'uninstall', 'addon' => $addon]);
|
||||
DBA::delete('addon', ['name' => $addon]);
|
||||
DI::config()->delete('addons', $addon);
|
||||
|
||||
@include_once('addon/' . $addon . '/' . $addon . '.php');
|
||||
if (function_exists($addon . '_uninstall')) {
|
||||
|
@ -168,12 +169,9 @@ class Addon
|
|||
$func(DI::app());
|
||||
}
|
||||
|
||||
DBA::insert('addon', [
|
||||
'name' => $addon,
|
||||
'installed' => true,
|
||||
'timestamp' => $t,
|
||||
'plugin_admin' => function_exists($addon . '_addon_admin'),
|
||||
'hidden' => file_exists('addon/' . $addon . '/.hidden')
|
||||
DI::config()->set('addons', $addon,[
|
||||
'last_update' => $t,
|
||||
'admin' => function_exists($addon . '_addon_admin'),
|
||||
]);
|
||||
|
||||
if (!self::isEnabled($addon)) {
|
||||
|
@ -190,20 +188,20 @@ class Addon
|
|||
*/
|
||||
public static function reload()
|
||||
{
|
||||
$addons = DBA::selectToArray('addon', [], ['installed' => true]);
|
||||
$addons = DI::config()->get('addons');
|
||||
|
||||
foreach ($addons as $addon) {
|
||||
$addonname = Strings::sanitizeFilePathItem(trim($addon['name']));
|
||||
foreach ($addons as $name => $data) {
|
||||
$addonname = Strings::sanitizeFilePathItem(trim($name));
|
||||
$addon_file_path = 'addon/' . $addonname . '/' . $addonname . '.php';
|
||||
if (file_exists($addon_file_path) && $addon['timestamp'] == filemtime($addon_file_path)) {
|
||||
if (file_exists($addon_file_path) && $data['last_update'] == filemtime($addon_file_path)) {
|
||||
// Addon unmodified, skipping
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger::debug("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $addon['name']]);
|
||||
Logger::debug("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $name]);
|
||||
|
||||
self::uninstall($addon['name']);
|
||||
self::install($addon['name']);
|
||||
self::uninstall($name);
|
||||
self::install($name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,11 +311,9 @@ class Addon
|
|||
public static function getVisibleList(): array
|
||||
{
|
||||
$visible_addons = [];
|
||||
$stmt = DBA::select('addon', ['name'], ['hidden' => false, 'installed' => true]);
|
||||
if (DBA::isResult($stmt)) {
|
||||
foreach (DBA::toArray($stmt) as $addon) {
|
||||
$visible_addons[] = $addon['name'];
|
||||
}
|
||||
$addons = DI::config()->get('addons');
|
||||
foreach ($addons as $name => $data) {
|
||||
$visible_addons[] = $name;
|
||||
}
|
||||
|
||||
return $visible_addons;
|
||||
|
|
|
@ -47,8 +47,8 @@ interface IManageConfigValues
|
|||
*
|
||||
* Get a particular config value from the given category ($cat)
|
||||
*
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param string $key The configuration key to query
|
||||
* @param string $cat The category of the configuration value
|
||||
* @param ?string $key The configuration key to query (if null, the whole array at the category will get returned)
|
||||
* @param mixed $default_value Deprecated, use `Config->get($cat, $key, null, $refresh) ?? $default_value` instead
|
||||
*
|
||||
* @return mixed Stored value or null if it does not exist
|
||||
|
@ -56,7 +56,7 @@ interface IManageConfigValues
|
|||
* @throws ConfigPersistenceException In case the persistence layer throws errors
|
||||
*
|
||||
*/
|
||||
public function get(string $cat, string $key, $default_value = null);
|
||||
public function get(string $cat, string $key = null, $default_value = null);
|
||||
|
||||
/**
|
||||
* Load all configuration values from a given cache and saves it back in the configuration node store
|
||||
|
|
|
@ -102,7 +102,7 @@ class Config implements IManageConfigValues
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function get(string $cat, string $key, $default_value = null)
|
||||
public function get(string $cat, string $key = null, $default_value = null)
|
||||
{
|
||||
return $this->configCache->get($cat, $key) ?? $default_value;
|
||||
}
|
||||
|
|
|
@ -85,10 +85,15 @@ class L10n
|
|||
* @var Database
|
||||
*/
|
||||
private $dba;
|
||||
/**
|
||||
* @var IManageConfigValues
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(IManageConfigValues $config, Database $dba, IHandleSessions $session, array $server, array $get)
|
||||
{
|
||||
$this->dba = $dba;
|
||||
$this->config = $config;
|
||||
|
||||
$this->loadTranslationTable(L10n::detectLanguage($server, $get, $config->get('system', 'language', self::DEFAULT)));
|
||||
$this->setSessionVariable($session);
|
||||
|
@ -157,9 +162,9 @@ class L10n
|
|||
$a->strings = [];
|
||||
|
||||
// load enabled addons strings
|
||||
$addons = $this->dba->select('addon', ['name'], ['installed' => true]);
|
||||
while ($p = $this->dba->fetch($addons)) {
|
||||
$name = Strings::sanitizeFilePathItem($p['name']);
|
||||
$addons = array_keys($this->config->get('addons') ?? []);
|
||||
foreach ($addons as $addon) {
|
||||
$name = Strings::sanitizeFilePathItem($addon);
|
||||
if (file_exists(__DIR__ . "/../../addon/$name/lang/$lang/strings.php")) {
|
||||
include __DIR__ . "/../../addon/$name/lang/$lang/strings.php";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue