diff --git a/config/services.yaml b/config/services.yaml index 8f9a1f50d8..4de258f1f4 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -24,10 +24,9 @@ services: App\Core\Router\RouteLoader: tags: ['routing.loader'] - # Wrapper arround Doctrine's StaticPHP metadata driver - app.core.schemadef_driver: - class: App\Core\DB\SchemaDefDriver + app.schemadef_driver: + class: App\DependencyInjection\Compiler\SchemaDefDriver arguments: - '%kernel.project_dir%/src/Entity' diff --git a/src/Core/ModuleManager.php b/src/Core/ModuleManager.php index 581629cd63..ec9ea77842 100644 --- a/src/Core/ModuleManager.php +++ b/src/Core/ModuleManager.php @@ -26,8 +26,8 @@ * @package GNUsocial * @category Modules * - * @author Hugo Sales - * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ @@ -100,20 +100,20 @@ class ModuleManager foreach ($module_paths as $path) { $type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path)); $dir = dirname($path); - $module = basename($dir); + $module = basename($dir); // component or plugin $fqcn = "\\{$type}\\{$module}\\{$module}"; $module_manager->add($fqcn, $path); if (!is_null($container) && file_exists($dir = $dir . '/Entity') && is_dir($dir)) { $entity_paths[] = $dir; $container->findDefinition('doctrine.orm.default_metadata_driver')->addMethodCall( 'addDriver', - [new Reference('app.core.schemadef_driver'), "{$type}\\{$module}\\Entity"] + [new Reference('app.schemadef_driver'), "{$type}\\{$module}\\Entity"] ); } } if (!is_null($container)) { - $container->findDefinition('app.core.schemadef_driver') + $container->findDefinition('app.schemadef_driver') ->addMethodCall('addPaths', ['$paths' => $entity_paths]); } diff --git a/src/Core/DB/SchemaDefDriver.php b/src/DependencyInjection/Compiler/SchemaDefDriver.php similarity index 83% rename from src/Core/DB/SchemaDefDriver.php rename to src/DependencyInjection/Compiler/SchemaDefDriver.php index 186d18261c..a527191ef1 100644 --- a/src/Core/DB/SchemaDefDriver.php +++ b/src/DependencyInjection/Compiler/SchemaDefDriver.php @@ -18,24 +18,43 @@ // }}} /** - * Doctrine metadata driver which implements our old `schemaDef` interface + * Compiler pass which triggers Symfony to tell Doctrine to + * use our `SchemaDef` metadata driver * - * @package GNUsocial + * @package GNUsocial * @category DB * - * @author Hugo Sales - * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -namespace App\Core\DB; +namespace App\DependencyInjection\Compiler; +use App\Core\Log; use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver; use Functional as F; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; -class SchemaDefDriver extends StaticPHPDriver +/** + * Register a new ORM driver to allow use to use the old (and better) schemaDef format + */ +class SchemaDefDriver extends StaticPHPDriver implements CompilerPassInterface { + /** + * Register `app.schemadef_driver` (this class instantiated with argument src/Entity) as a metadata driver + */ + public function process(ContainerBuilder $container) + { + $container->findDefinition('doctrine.orm.default_metadata_driver') + ->addMethodCall('addDriver', + [new Reference('app.schemadef_driver'), 'App\\Entity'] + ); + } + /** * V2 DB type => Doctrine type */ @@ -75,6 +94,8 @@ class SchemaDefDriver extends StaticPHPDriver { $schema = $class_name::schemaDef(); + Log::emergency($class_name); + $metadata->setPrimaryTable([ 'name' => $schema['name'], 'indexes' => self::kv_to_name_col($schema['indexes'] ?? []), diff --git a/src/DependencyInjection/Compiler/SchemaDefPass.php b/src/DependencyInjection/Compiler/SchemaDefPass.php deleted file mode 100644 index 1e1e7aeae5..0000000000 --- a/src/DependencyInjection/Compiler/SchemaDefPass.php +++ /dev/null @@ -1,50 +0,0 @@ -. -// }}} - -/** - * Compiler pass which triggers Symfony to tell Doctrine to - * use out `SchemaDef` metadata driver - * - * @package GNUsocial - * @category DB - * - * @author Hugo Sales - * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org - * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later - */ - -namespace App\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -/** - * Register a new ORM driver to allow use to use the old (and better) schemaDef format - */ -class SchemaDefPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container) - { - $container->findDefinition('doctrine.orm.default_metadata_driver') - ->addMethodCall('addDriver', - [new Reference('app.core.schemadef_driver'), 'App\\Entity'] - ); - } -} diff --git a/src/Kernel.php b/src/Kernel.php index f3eea69e57..b4ebc57e6c 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -23,15 +23,15 @@ * @package GNUsocial * @category Kernel * - * @author Hugo Sales - * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App; use App\DependencyInjection\Compiler\ModuleManagerPass; -use App\DependencyInjection\Compiler\SchemaDefPass; +use App\DependencyInjection\Compiler\SchemaDefDriver; use const PHP_VERSION_ID; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\LoaderInterface; @@ -152,6 +152,6 @@ class Kernel extends BaseKernel parent::build($container); $container->addCompilerPass(new ModuleManagerPass()); - $container->addCompilerPass(new SchemaDefPass()); + $container->addCompilerPass(new SchemaDefDriver(SRCDIR . '/Entity')); } }