/** * @param Entity\User $user * @return void * @throws \LogicException If needed role can not be found */ public function updateUserToKeyRole(Entity\User $user) { /** @var \Secretary\Entity\Role $roleRecord */ $roleRecord = $this->getRoleRepository()->findOneBy(array('roleId' => 'keyuser')); if (empty($roleRecord)) { throw new \LogicException('Roles are missing, please configure them'); } $user->getRoles()->clear(); $user->addRole($roleRecord); $this->em->persist($user); $this->em->flush(); return; }
/** * {@inheritDoc} */ public function addRole(\Secretary\Entity\Role $role) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'addRole', array($role)); return parent::addRole($role); }