diff --git a/src/Command/UpdateEntityInterventionCommand.php b/src/Command/UpdateEntityInterventionCommand.php index 6b50d51..aa9a9b8 100644 --- a/src/Command/UpdateEntityInterventionCommand.php +++ b/src/Command/UpdateEntityInterventionCommand.php @@ -10,47 +10,45 @@ use Symfony\Component\Console\Output\OutputInterface; class UpdateEntityInterventionCommand extends Command { - private $em; + public function __construct( + protected EntityManager $entityManager, + protected InterventionRepositoryQuery $interventionQuery + ) + { + parent::__construct(); + } - private $interventionQuery; + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('update:entity:intervention') + ->setDescription('Update entity intervention between 2 migrations. Adding field establishmentGroup and removingEstablishmentGroups') + ->setHelp('') + ; + } - public function __construct(EntityManager $entityManager, InterventionRepositoryQuery $interventionQuery) - { - parent::__construct(); + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $interventions = $this->interventionQuery->create()->find(); - $this->em = $entityManager; - $this->interventionQuery = $interventionQuery; - } + foreach ($interventions as $intervention) { + if (null !== $intervention->getEstablishmentGroupsOld()->first()) { + $intervention->setEstablishmentGroup($intervention->getEstablishmentGroupsOld()[0]); - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('update:entity:intervention') - ->setDescription('Update entity intervention between 2 migrations. Adding field establishmentGroup and removingEstablishmentGroups') - ->setHelp(''); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $interventions = $this->interventionQuery->create()->find(); - - foreach ($interventions as $intervention){ - if($intervention->getEstablishmentGroupsOld()->first()!==null) { - $intervention->setEstablishmentGroup($intervention->getEstablishmentGroupsOld()[0]); - $this->em->update($intervention); - } + $this->entityManager->update($intervention, flush: false); } - $this->em->flush(); - $output->writeln('Les entités interventions ont été mis à jour. Exécuter de nouveau la migration suivante. '); - return Command::SUCCESS; - - } + $this->entityManager->flush(); + + $output->writeln('Les entités interventions ont été mis à jour. Exécuter de nouveau la migration suivante. '); + + return Command::SUCCESS; + } }