Exemple #1
0
 /**
  * @param array $values
  * @param Page|null $page
  * @return Page
  * @throws UrlAlreadyExistsException
  * @throws LocaleNotFoundException
  * @throws PageTitleAlreadyExistsException
  * @throws PageIntroHtmlLengthException
  */
 private function createNewPage(array $values, Page $page = null)
 {
     $this->em->beginTransaction();
     $url = $this->establishPageUrl($values['title'], $values['url']);
     $url = $this->urlFacade->saveUrl($url);
     // still needs internalID to be set! (next in code)
     $locale = $this->localeFacade->getByName($values['lang']);
     if ($locale === null) {
         throw new LocaleNotFoundException();
     }
     if ($page === null) {
         $page = new Page($values['title'], $values['intro'], $values['text'], $url, $values['author'], $locale);
     }
     $this->fillPageEntity($values, $page);
     /** @var Page $page */
     $page = $this->em->safePersist($page);
     if ($page === false) {
         throw new PageTitleAlreadyExistsException();
     }
     $url->setInternalId($page->getId());
     $this->em->persist($url);
     $this->addTags2Page($values['tags'], $page);
     $this->em->persist($page);
     $this->em->flush();
     $this->em->commit();
     return $page;
 }