Example #1
0
 /**
  * @param string $newUrlAddress
  * @param Page $page
  * @return Url
  * @throws UrlAlreadyExistsException
  */
 private function redirectPageToUrl($newUrlAddress, Page $page)
 {
     $newUrlEntity = $this->createUrl($newUrlAddress);
     $newUrlEntity->setInternalId($page->getId());
     // if we first try to save url entity, the current transaction is marked for
     // rollback only if there is unique constraint violation.
     $newUrl = $this->urlFacade->getByPath($newUrlEntity->getUrlPath());
     if ($newUrl === null) {
         $newUrl = $this->urlFacade->saveUrl($newUrlEntity);
     }
     $oldUrl = $this->urlFacade->getById($page->getUrlId());
     $this->urlFacade->linkUrls($oldUrl, $newUrl);
     return $newUrl;
 }