/** * Load users * * @return void */ public function loadUsers() { for ($i = 0; $i < self::USERS_NUMBER; ++$i) { $firstName = $this->generateFirstName(); $lastName = $this->generateLastName(); $middleName = $this->generateMiddleName(); $birthday = $this->generateBirthday(); $username = $this->generateUsername($firstName, $lastName); $email = $this->generateEmail($firstName, $lastName); $user = $this->createUser($username, $email, $firstName, $lastName, $middleName, $birthday, $this->organization); $user->setPlainPassword($username); $this->userManager->updatePassword($user); $this->persist($user); } $this->flush(); }
/** * Load users * * @return void */ public function loadUsers() { for ($i = 0; $i < 50; ++$i) { $firstName = $this->generateFirstName(); $lastName = $this->generateLastName(); $birthday = $this->generateBirthday(); $username = $this->generateUsername($firstName, $lastName); $email = $this->generateEmail($firstName, $lastName); $user = $this->createUser($username, $email, $firstName, $lastName, $birthday, $this->role); $user->setPlainPassword($username); $this->userManager->updatePassword($user); $this->persist($user); if ($i % self::FLUSH_MAX == 0) { $this->flush(); $this->em->clear(); $this->initSupportingEntities(); } } $this->flush(); }
/** * @param UserInterface $user * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(UserInterface $user, $field, $data) { switch ($field) { case 'username': $user->setUsername($data); break; case 'name_prefix': $user->setNamePrefix($data); break; case 'first_name': $user->setFirstName($data); break; case 'middle_name': $user->setMiddleName($data); break; case 'last_name': $user->setLastName($data); break; case 'name_suffix': $user->setNameSuffix($data); break; case 'email': $user->setEmail($data); break; case 'password': $user->setPlainPassword($data); $this->userManager->updatePassword($user); break; case 'birthday': $user->setBirthday(new \DateTime($data, \DateTime::ISO8601)); break; case 'email_notifications': $user->setEmailNotifications($data); break; case 'catalog_locale': $user->setCatalogLocale($this->findLocale($data)); break; case 'user_locale': $user->setUiLocale($this->findLocale($data)); break; case 'catalog_scope': $user->setCatalogScope($this->findChannel($data)); break; case 'default_tree': $user->setDefaultTree($this->findCategory($data)); break; case 'roles': foreach ($data as $code) { $role = $this->findRole($code); $user->addRole($role); } break; case 'groups': foreach ($data as $code) { $role = $this->findGroup($code); $user->addGroup($role); } break; case 'api_key': if (null === ($api = $user->getApi())) { $api = new UserApi(); } $api->setApiKey($data)->setUser($user); $user->setApi($api); break; } }