Add option to create mutiple and fix delete
This commit is contained in:
		| @@ -45,17 +45,21 @@ abstract class AbstractEntityCommand extends Command | |||||||
|         $this->getConfig($builder); |         $this->getConfig($builder); | ||||||
|  |  | ||||||
|         if ($input->getOption('create')) { |         if ($input->getOption('create')) { | ||||||
|  |             do { | ||||||
|                 $io->info(sprintf('Creating new "%s"', $this->getEntityClass())); |                 $io->info(sprintf('Creating new "%s"', $this->getEntityClass())); | ||||||
|                 $entity = new ($this->getEntityClass())(); |                 $entity = new ($this->getEntityClass())(); | ||||||
|                 $builder->setAll($entity); |                 $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)))) { |                 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())); |                     $io->success(sprintf('Object "%s" (id: %s) stored successfully', $entity, $entity->getId())); | ||||||
|                 } |                 } | ||||||
|  |             } while ($io->askQuestion(new ConfirmationQuestion('Create another?', false))); | ||||||
|         } elseif ($input->getOption('modify')) { |         } elseif ($input->getOption('modify')) { | ||||||
|             $io->info(sprintf('Modifying "%s"', $this->getEntityClass())); |             $io->info(sprintf('Modifying "%s"', $this->getEntityClass())); | ||||||
|             $entity = $this->select($io, $id); |             $entity = $this->select($io, $id); | ||||||
|             $builder->setByQuestion($entity); |             $builder->setByQuestion($entity); | ||||||
|  |             $this->em->persist($entity); | ||||||
|         } elseif ($input->getOption('delete')) { |         } elseif ($input->getOption('delete')) { | ||||||
|             $io->info(sprintf('Deleting "%s"', $this->getEntityClass())); |             $io->info(sprintf('Deleting "%s"', $this->getEntityClass())); | ||||||
|             $entity = $this->select($io, $id); |             $entity = $this->select($io, $id); | ||||||
| @@ -77,7 +81,6 @@ abstract class AbstractEntityCommand extends Command | |||||||
|             return Command::INVALID; |             return Command::INVALID; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $this->em->persist($entity); |  | ||||||
|         $this->em->flush(); |         $this->em->flush(); | ||||||
|  |  | ||||||
|         return Command::SUCCESS; |         return Command::SUCCESS; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user