Beispiel #1
0
 /**
  * @param Url $oldUrl
  * @param Url $newUrl
  * @return void
  * @throws \Exception
  */
 public function linkUrls(Url $oldUrl, Url $newUrl)
 {
     if ($oldUrl->getId() === null or $newUrl->getId() === null) {
         throw new UrlNotPersistedException();
     }
     try {
         $this->em->beginTransaction();
         $alreadyRedirectedUrls = $this->findByActualUrl($oldUrl->getId());
         /** @var Url $url */
         foreach ($alreadyRedirectedUrls as $url) {
             $url->setRedirectTo($newUrl);
             $this->em->persist($url);
             $this->cache->clean([Cache::TAGS => [$url->getCacheKey()]]);
         }
         $oldUrl->setRedirectTo($newUrl);
         $this->em->persist($oldUrl);
         $this->cache->clean([Cache::TAGS => [$oldUrl->getCacheKey()]]);
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
Beispiel #2
0
 public function getCurrentUrlId()
 {
     if (!isset($this->actualUrlToRedirect)) {
         return $this->getId();
     }
     return $this->actualUrlToRedirect->getId();
 }
Beispiel #3
0
 /**
  * @param Url $url
  * @return Url
  * @throws UrlAlreadyExistsException
  * @throws \Exception
  */
 public function save(Url $url)
 {
     try {
         $this->em->beginTransaction();
         if ($url->getId() !== null) {
             $url = $this->update($url);
         } else {
             $url = $this->create($url);
         }
         $this->em->commit();
     } catch (UrlAlreadyExistsException $uae) {
         $this->closeEntityManager();
         $this->logger->addError(sprintf('Url path already exists: %s', $uae));
         throw $uae;
     } catch (\Exception $e) {
         $this->closeEntityManager();
         $this->logger->addError(sprintf('Url Entity saving failure: %s', $e));
         throw $e;
     }
     return $url;
 }
Beispiel #4
0
 /**
  * @return int
  */
 public function getUrlId()
 {
     return $this->url->getId();
 }