function saveUser($token) { $repository = $this->em->getRepository('AppBundle:Users'); $fbUser = $this->getFBUser($token); $user = $repository->findOneByIdFacebook($fbUser->getId()); if (!is_object($user)) { $newUser = new Users(); $newUser->setIdFacebook($fbUser->getId()); $newUser->setBirthday($fbUser->getField('age_range')['min']); $newUser->setEmail($fbUser->getEmail()); $newUser->setGender($fbUser->getGender()); $newUser->setNom($fbUser->getLastName()); $newUser->setPrenom($fbUser->getFirstName()); $newUser->setToken($token); $this->em->persist($newUser); $this->em->flush(); } else { $user->setToken($token); $this->em->persist($user); $this->em->flush(); } }