/** * @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; }
/** * @param Tag $tag */ private function createUrl(Tag $tag) { $url = UrlGenerator::create(sprintf('search/%s', $tag->getName()), 'Pages:Front:Search', 'tag', $tag->getId()); $this->urlFacade->saveUrl($url); }