コード例 #1
0
ファイル: UserPersister.php プロジェクト: blitzik/CMS
 /**
  * @param array $values
  * @param User|null $user
  * @return ValidationObject
  */
 public function update(array $values, User $user)
 {
     $this->em->beginTransaction();
     $user->setFirstName($values['first_name']);
     $user->setLastName($values['last_name']);
     $validationObject = new ValidationObject();
     // todo could be optimized
     $user->clearRoles();
     $role = $this->getRole($values['role'], $validationObject);
     if (!$validationObject->isValid()) {
         $this->em->rollback();
         return $validationObject;
     }
     $user->addRole($role);
     $this->em->persist($user);
     $this->em->flush();
     if ($validationObject->isValid()) {
         $this->em->commit();
         $this->onSuccessUserEditing($user);
         $this->cache->remove($user->getCacheKey());
     } else {
         $this->em->rollback();
     }
     return $validationObject;
 }