From 230c50a95fefe86af53953a68b776c279918f3da Mon Sep 17 00:00:00 2001 From: Marek Rzytki Date: Mon, 3 Jun 2024 10:38:29 +0200 Subject: [PATCH] Add migrations prepend to plugin extension class --- .../BitBagSyliusMailTemplateExtension.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/BitBagSyliusMailTemplateExtension.php b/src/DependencyInjection/BitBagSyliusMailTemplateExtension.php index 5ef9ed3..7e8eb2a 100644 --- a/src/DependencyInjection/BitBagSyliusMailTemplateExtension.php +++ b/src/DependencyInjection/BitBagSyliusMailTemplateExtension.php @@ -15,9 +15,10 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -final class BitBagSyliusMailTemplateExtension extends Extension +final class BitBagSyliusMailTemplateExtension extends Extension implements PrependExtensionInterface { public const ALLOWED_FILTERS_PARAMETER = 'bitbag_sylius_mail_template_plugin.mail_template.twig.allowed_filters'; @@ -71,4 +72,36 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co { return new Configuration(); } + + public function prepend(ContainerBuilder $container) + { + if (!$container->hasExtension('doctrine_migrations') || !$container->hasExtension('sylius_labs_doctrine_migrations_extra')) { + return; + } + + if ( + $container->hasParameter('sylius_core.prepend_doctrine_migrations') && + false === $container->getParameter('sylius_core.prepend_doctrine_migrations') + ) { + return; + } + + /** @var array $doctrineConfig */ + $doctrineConfig = $container->getExtensionConfig('doctrine_migrations'); + $migrationsPath = (array) \array_pop($doctrineConfig)['migrations_paths']; + $container->prependExtensionConfig('doctrine_migrations', [ + 'migrations_paths' => \array_merge( + $migrationsPath, + [ + 'BitBag\MailTemplatePlugin\Migrations' => '@BitBagSyliusMailTemplatePlugin/Migrations', + ], + ), + ]); + + $container->prependExtensionConfig('sylius_labs_doctrine_migrations_extra', [ + 'migrations' => [ + 'BitBag\MailTemplatePlugin\Migrations' => ['Sylius\Bundle\CoreBundle\Migrations'], + ], + ]); + } }