diff --git a/packages/entity-migrator/Command/BaseCommand.php b/packages/entity-migrator/Command/BaseCommand.php index 460e30fab..4f170467e 100644 --- a/packages/entity-migrator/Command/BaseCommand.php +++ b/packages/entity-migrator/Command/BaseCommand.php @@ -11,13 +11,15 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; abstract class BaseCommand extends Command { public function __construct( protected Migrator $migrator, protected EntityMigrationRepository $entityMigrationRepository, - protected ManagerRegistry $managerRegistry + protected ManagerRegistry $managerRegistry, + protected ?ServicesResetter $servicesResetter = null ) { parent::__construct(); } diff --git a/packages/entity-migrator/Command/MigrateCommand.php b/packages/entity-migrator/Command/MigrateCommand.php index 93686e21a..9156bc865 100644 --- a/packages/entity-migrator/Command/MigrateCommand.php +++ b/packages/entity-migrator/Command/MigrateCommand.php @@ -65,6 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progress->advance(); $manager->clear(); + + $this->servicesResetter?->reset(); } $progress->finish(); diff --git a/packages/entity-migrator/Command/QueueBatchCommand.php b/packages/entity-migrator/Command/QueueBatchCommand.php index 375f13c80..017059e9a 100644 --- a/packages/entity-migrator/Command/QueueBatchCommand.php +++ b/packages/entity-migrator/Command/QueueBatchCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; use Symfony\Component\Messenger\MessageBusInterface; #[AsCommand( @@ -26,12 +27,13 @@ class QueueBatchCommand extends BaseCommand { public function __construct( + private MessageBusInterface $messageBus, Migrator $migrator, EntityMigrationRepository $entityMigrationRepository, ManagerRegistry $managerRegistry, - private MessageBusInterface $messageBus + ?ServicesResetter $servicesResetter = null, ) { - parent::__construct($migrator, $entityMigrationRepository, $managerRegistry); + parent::__construct($migrator, $entityMigrationRepository, $managerRegistry, $servicesResetter); } protected function configure(): void @@ -136,6 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $manager->clear(); $progress->advance(); + $this->servicesResetter?->reset(); } $progress->finish(); diff --git a/packages/framework-extra-bundle/DependencyInjection/Integration/EntityMigratorIntegration.php b/packages/framework-extra-bundle/DependencyInjection/Integration/EntityMigratorIntegration.php index 955c9170a..2a169c1e2 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Integration/EntityMigratorIntegration.php +++ b/packages/framework-extra-bundle/DependencyInjection/Integration/EntityMigratorIntegration.php @@ -2,6 +2,8 @@ namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration; +use Draw\Component\EntityMigrator\Command\MigrateCommand; +use Draw\Component\EntityMigrator\Command\QueueBatchCommand; use Draw\Component\EntityMigrator\Entity\BaseEntityMigration; use Draw\Component\EntityMigrator\Entity\EntityMigrationInterface; use Draw\Component\EntityMigrator\Entity\Migration; @@ -11,6 +13,7 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; +use Symfony\Component\DependencyInjection\Reference; class EntityMigratorIntegration implements IntegrationInterface, PrependIntegrationInterface { @@ -33,6 +36,14 @@ public function load(array $config, PhpFileLoader $loader, ContainerBuilder $con \dirname((new \ReflectionClass(Migrator::class))->getFileName()), ); + $container + ->getDefinition(MigrateCommand::class) + ->setArgument('$servicesResetter', new Reference('services_resetter')); + + $container + ->getDefinition(QueueBatchCommand::class) + ->setArgument('$servicesResetter', new Reference('services_resetter')); + $this->renameDefinitions( $container, $namespace,