use murph entity manager instead of doctrine entity manager
This commit is contained in:
parent
f15ad839f6
commit
c05a02d924
1 changed files with 37 additions and 39 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue