From 501175a1defbd4cd9581c3dad05975fbe19f931b Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 28 Sep 2022 14:43:22 +0200 Subject: [PATCH] Add option to create mutiple and fix delete --- src/EntityBuilder/AbstractEntityCommand.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/EntityBuilder/AbstractEntityCommand.php b/src/EntityBuilder/AbstractEntityCommand.php index 2debeb4..c4fb635 100644 --- a/src/EntityBuilder/AbstractEntityCommand.php +++ b/src/EntityBuilder/AbstractEntityCommand.php @@ -45,17 +45,21 @@ abstract class AbstractEntityCommand extends Command $this->getConfig($builder); if ($input->getOption('create')) { - $io->info(sprintf('Creating new "%s"', $this->getEntityClass())); - $entity = new ($this->getEntityClass())(); - $builder->setAll($entity); + do { + $io->info(sprintf('Creating new "%s"', $this->getEntityClass())); + $entity = new ($this->getEntityClass())(); + $builder->setAll($entity); + $this->em->persist($entity); - if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to create %s with above properties', $entity)))) { - $io->success(sprintf('Object "%s" (id: %s) stored successfully', $entity, $entity->getId())); - } + if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to create %s with above properties', $entity)))) { + $io->success(sprintf('Object "%s" (id: %s) stored successfully', $entity, $entity->getId())); + } + } while ($io->askQuestion(new ConfirmationQuestion('Create another?', false))); } elseif ($input->getOption('modify')) { $io->info(sprintf('Modifying "%s"', $this->getEntityClass())); $entity = $this->select($io, $id); $builder->setByQuestion($entity); + $this->em->persist($entity); } elseif ($input->getOption('delete')) { $io->info(sprintf('Deleting "%s"', $this->getEntityClass())); $entity = $this->select($io, $id); @@ -77,7 +81,6 @@ abstract class AbstractEntityCommand extends Command return Command::INVALID; } - $this->em->persist($entity); $this->em->flush(); return Command::SUCCESS;