[MODULES] Fix module manager dev-mode rebuild

This commit is contained in:
Hugo Sales 2020-09-10 20:42:17 +00:00 committed by Hugo Sales
parent c8b6db650a
commit e0672e559a
3 changed files with 15 additions and 10 deletions

View File

@ -75,10 +75,11 @@ class SchemaDefDriver extends StaticPHPDriver
{
$schema = $class_name::schemaDef();
$metadata->setPrimaryTable(['name' => $schema['name'],
'indexes' => self::kv_to_name_col($schema['indexes'] ?? []),
'uniqueConstraints' => self::kv_to_name_col($schema['unique keys'] ?? []),
'options' => ['comment' => $schema['description'] ?? ''],
$metadata->setPrimaryTable([
'name' => $schema['name'],
'indexes' => self::kv_to_name_col($schema['indexes'] ?? []),
'uniqueConstraints' => self::kv_to_name_col($schema['unique keys'] ?? []),
'options' => ['comment' => $schema['description'] ?? ''],
]);
foreach ($schema['fields'] as $name => $opts) {

View File

@ -137,6 +137,8 @@ class GNUsocial implements EventSubscriberInterface
HTTPClient::setClient($this->client);
if (isset($_ENV['HTTPS']) || isset($_ENV['HTTP_HOST'])) {
// TODO move to container definition, after removing
// this way of doing configuration
DefaultSettings::setDefaults();
}

View File

@ -83,12 +83,11 @@ class ModuleManager
}
}
public static function process(ContainerBuilder $container)
public static function process(?ContainerBuilder $container = null)
{
$module_paths = array_merge(glob(INSTALLDIR . '/components/*/*.php'), glob(INSTALLDIR . '/plugins/*/*.php'));
$module_manager = new self();
$entity_paths = [];
$default_driver = $container->findDefinition('doctrine.orm.default_metadata_driver');
foreach ($module_paths as $path) {
// 'modules' and 'plugins' have the same length
$type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path));
@ -96,17 +95,19 @@ class ModuleManager
$module = basename($dir);
$fqcn = "\\{$type}\\{$module}\\{$module}";
$module_manager->add($fqcn, $path);
if (file_exists($dir = $dir . '/Entity') && is_dir($dir)) {
if (!is_null($container) && file_exists($dir = $dir . '/Entity') && is_dir($dir)) {
$entity_paths[] = $dir;
$default_driver->addMethodCall(
$container->findDefinition('doctrine.orm.default_metadata_driver')->addMethodCall(
'addDriver',
[new Reference('app.core.schemadef_driver'), "{$type}\\{$module}\\Entity"]
);
}
}
$container->findDefinition('app.core.schemadef_driver')
->addMethodCall('addPaths', ['$paths' => $entity_paths]);
if (!is_null($container)) {
$container->findDefinition('app.core.schemadef_driver')
->addMethodCall('addPaths', ['$paths' => $entity_paths]);
}
$module_manager->preRegisterEvents();
@ -132,6 +133,7 @@ class ModuleManager
$time = file_exists(CACHE_FILE) ? filemtime(CACHE_FILE) : 0;
if (F\some($rdi, function ($e) use ($time) { return $e->getMTime() > $time; })) {
Log::info('Rebuilding plugin cache at runtime. This means we can\'t update DB definitions');
self::process();
}
}