Skip to content

Commit

Permalink
[EntityMigrator] use service resetter in migrate and batch queue
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Nov 1, 2023
1 parent 8932d56 commit fbeab6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/entity-migrator/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions packages/entity-migrator/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$progress->advance();

$manager->clear();

$this->servicesResetter?->reset();
}

$progress->finish();
Expand Down
7 changes: 5 additions & 2 deletions packages/entity-migrator/Command/QueueBatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -136,6 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$manager->clear();

$progress->advance();
$this->servicesResetter?->reset();
}

$progress->finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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,
Expand Down

0 comments on commit fbeab6b

Please sign in to comment.