[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,7 +75,8 @@ class SchemaDefDriver extends StaticPHPDriver
{ {
$schema = $class_name::schemaDef(); $schema = $class_name::schemaDef();
$metadata->setPrimaryTable(['name' => $schema['name'], $metadata->setPrimaryTable([
'name' => $schema['name'],
'indexes' => self::kv_to_name_col($schema['indexes'] ?? []), 'indexes' => self::kv_to_name_col($schema['indexes'] ?? []),
'uniqueConstraints' => self::kv_to_name_col($schema['unique keys'] ?? []), 'uniqueConstraints' => self::kv_to_name_col($schema['unique keys'] ?? []),
'options' => ['comment' => $schema['description'] ?? ''], 'options' => ['comment' => $schema['description'] ?? ''],

View File

@ -137,6 +137,8 @@ class GNUsocial implements EventSubscriberInterface
HTTPClient::setClient($this->client); HTTPClient::setClient($this->client);
if (isset($_ENV['HTTPS']) || isset($_ENV['HTTP_HOST'])) { if (isset($_ENV['HTTPS']) || isset($_ENV['HTTP_HOST'])) {
// TODO move to container definition, after removing
// this way of doing configuration
DefaultSettings::setDefaults(); 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_paths = array_merge(glob(INSTALLDIR . '/components/*/*.php'), glob(INSTALLDIR . '/plugins/*/*.php'));
$module_manager = new self(); $module_manager = new self();
$entity_paths = []; $entity_paths = [];
$default_driver = $container->findDefinition('doctrine.orm.default_metadata_driver');
foreach ($module_paths as $path) { foreach ($module_paths as $path) {
// 'modules' and 'plugins' have the same length // 'modules' and 'plugins' have the same length
$type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path)); $type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path));
@ -96,17 +95,19 @@ class ModuleManager
$module = basename($dir); $module = basename($dir);
$fqcn = "\\{$type}\\{$module}\\{$module}"; $fqcn = "\\{$type}\\{$module}\\{$module}";
$module_manager->add($fqcn, $path); $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; $entity_paths[] = $dir;
$default_driver->addMethodCall( $container->findDefinition('doctrine.orm.default_metadata_driver')->addMethodCall(
'addDriver', 'addDriver',
[new Reference('app.core.schemadef_driver'), "{$type}\\{$module}\\Entity"] [new Reference('app.core.schemadef_driver'), "{$type}\\{$module}\\Entity"]
); );
} }
} }
if (!is_null($container)) {
$container->findDefinition('app.core.schemadef_driver') $container->findDefinition('app.core.schemadef_driver')
->addMethodCall('addPaths', ['$paths' => $entity_paths]); ->addMethodCall('addPaths', ['$paths' => $entity_paths]);
}
$module_manager->preRegisterEvents(); $module_manager->preRegisterEvents();
@ -132,6 +133,7 @@ class ModuleManager
$time = file_exists(CACHE_FILE) ? filemtime(CACHE_FILE) : 0; $time = file_exists(CACHE_FILE) ? filemtime(CACHE_FILE) : 0;
if (F\some($rdi, function ($e) use ($time) { return $e->getMTime() > $time; })) { 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(); self::process();
} }
} }