[CORE] Fix loading of settings from modules

This commit is contained in:
Hugo Sales 2021-11-08 15:05:55 +00:00 committed by Diogo Peralta Cordeiro
parent 019ad794d1
commit cd470cbf93
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 15 additions and 10 deletions

View File

@ -236,16 +236,17 @@ class GNUsocial implements EventSubscriberInterface
// Load .local
$loader->load($local_file);
$locals = $container->getParameter('locals');
$container->getParameterBag()->remove('locals');
// Load normal config
$loader->load(INSTALLDIR . '/social' . Kernel::CONFIG_EXTS, 'glob');
$container->setParameter('gnusocial_defaults', $container->getParameter('gnusocial'));
$defaults = $container->getParameter('gnusocial');
// Load module config
$parameters = ModuleManager::configureContainer($container, $loader);
$module_configs = ModuleManager::configureContainer($container, $loader);
// Merge parameter $from with values already set in $to
$merge_config = function ($from, $to = null) use ($container, $locals) {
$merge_local_config = function ($from, $to = null) use ($container, $locals) {
$to ??= $from;
$wrapper = $container->hasParameter($to) ? $container->getParameter($to) : [];
$content = [$from => $container->getParameter($from)];
@ -257,11 +258,15 @@ class GNUsocial implements EventSubscriberInterface
// Override and merge any of the previous settings from the locals
if (\is_array($locals)) {
$merge_config('gnusocial');
foreach ($parameters as $mod => $type) {
$merge_config($mod, $type);
$merge_local_config('gnusocial');
foreach ($module_configs as $mod => $type) {
$loader->load(INSTALLDIR . \PATH_SEPARATOR . $type . \PATH_SEPARATOR . ucfirst($mod) . 'config' . Kernel::CONFIG_EXTS, 'glob');
$defaults[$mod] = $container->getParameter($mod);
$merge_local_config($mod, $type); // TODO likely broken
}
}
$container->setParameter('gnusocial_defaults', $defaults);
$container->setParameter('gnusocial', $defaults);
}
/**

View File

@ -197,17 +197,17 @@ class ModuleManager
$container->loadFromExtension('twig', ['paths' => $templates]);
$modules = array_merge(glob(INSTALLDIR . '/components/*'), glob(INSTALLDIR . '/plugins/*'));
$parameters = [];
$module_configs = [];
foreach ($modules as $mod) {
$path = "{$mod}/config" . Kernel::CONFIG_EXTS;
$loader->load($path, 'glob'); // Is supposed to, but doesn't return anything that would let us identify if loading worked
foreach (explode(',', mb_substr(Kernel::CONFIG_EXTS, 2, -1)) as $ext) {
if (file_exists("{$mod}/config.{$ext}")) {
$parameters[basename(mb_strtolower($mod))] = basename(\dirname(mb_strtolower($mod)));
$module_configs[basename(mb_strtolower($mod))] = basename(\dirname(mb_strtolower($mod)));
break;
}
}
}
return $parameters;
return $module_configs;
}
}