protected function insertUsers(InputInterface $input, OutputInterface $output) { if ($lastUser = $this->doctrine->getRepository('AppBundle:Person')->findOneBy([], ['id' => 'DESC'])) { $startId = $lastUser->getId(); } else { $startId = 0; } $em = $this->doctrine->getManager(); $usercount = $startId + $input->getArgument('usercount'); $faker = \Faker\Factory::create(); for ($i = $startId; $i < $usercount; $i++) { $person = new Person(); $person->setUsername(sprintf('exampleuser%d', $i))->setFirstname($faker->firstName)->setLastname($faker->lastName)->setPassword('password')->setEmail($faker->safeEmail); $output->writeln(sprintf('<info>Added user %s (%s %s)</info>', $person->getUsername(), $person->getFirstname(), $person->getLastname())); $em->persist($person); $em->flush(); } }
/** * Turn this item object into a generic array * * @return array */ public function transform(Person $person) { return ['id' => (int) $person->getId(), 'firstname' => $person->getFirstname(), 'lastname' => $person->getLastname(), 'email' => $person->getEmail(), 'organizationId' => $person->getOrganization()->getId(), 'fileCount' => $person->getNumFiles(), 'createdAt' => $person->getCreatedAt(), 'updatedAt' => $person->getUpdatedAt()]; }