Set creator.
public setCreator ( Sulu\Component\Security\Authentication\UserInterface $creator = null ) : |
||
$creator | Sulu\Component\Security\Authentication\UserInterface | |
return |
public function setUp() { parent::setUp(); $this->purgeDatabase(); $this->initPhpcr(); $this->mapper = $this->getContainer()->get('sulu.content.mapper'); $this->structureManager = $this->getContainer()->get('sulu.content.structure_manager'); $this->webspaceManager = $this->getContainer()->get('sulu_core.webspace.webspace_manager'); $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session'); $this->contentQuery = $this->getContainer()->get('sulu.content.query_executor'); $this->languageNamespace = $this->getContainer()->getParameter('sulu.content.language.namespace'); $em = $this->getContainer()->get('doctrine')->getManager(); $user = $em->getRepository('Sulu\\Bundle\\SecurityBundle\\Entity\\User')->findOneByUsername('test'); $this->tag1 = new Tag(); $this->tag1->setName('test1'); $this->tag1->setCreator($user); $this->tag1->setChanger($user); $em->persist($this->tag1); $this->tag2 = new Tag(); $this->tag2->setName('test2'); $this->tag2->setCreator($user); $this->tag2->setChanger($user); $em->persist($this->tag2); $this->tag3 = new Tag(); $this->tag3->setName('test3'); $this->tag3->setCreator($user); $this->tag3->setChanger($user); $em->persist($this->tag3); $em->flush(); }
/** * {@inheritdoc} */ public function save($data, $userId, $id = null) { $name = $data['name']; try { // load existing tag if id is given and create a new one otherwise if ($id) { $tag = $this->tagRepository->findTagById($id); if (!$tag) { throw new TagNotFoundException($id); } } else { $tag = new Tag(); } $user = $this->userRepository->findUserById($userId); // update data $tag->setName($name); $tag->setChanger($user); if (!$id) { $tag->setCreator($user); $this->em->persist($tag); } $this->em->flush(); return $tag; } catch (DBALException $exc) { if ($exc->getPrevious()->getCode() == 23000) { // Check if unique constraint fails throw new TagAlreadyExistsException($name); } else { throw $exc; } } }
/** * {@inheritdoc} */ public function save($data, $userId, $id = null) { $name = $data['name']; try { // load existing tag if id is given and create a new one otherwise if ($id) { $tag = $this->tagRepository->findTagById($id); if (!$tag) { throw new TagNotFoundException($id); } } else { $tag = new Tag(); } $user = $this->userRepository->findUserById($userId); // update data $tag->setName($name); $tag->setChanger($user); if (!$id) { $tag->setCreator($user); $this->em->persist($tag); } $this->em->flush(); return $tag; } catch (UniqueConstraintViolationException $exc) { throw new TagAlreadyExistsException($name); } }