Exemplo n.º 1
0
 /**
  * @param RedirectInterface $redirect
  * @return RedirectInterface
  */
 public static function create(RedirectInterface $redirect)
 {
     return new self($redirect->getSourceUriPath(), $redirect->getTargetUriPath(), $redirect->getStatusCode(), $redirect->getHost());
 }
 /**
  * @param string $prefix
  * @param RedirectInterface $redirect
  * @return void
  */
 protected function outputRedirectLine($prefix, RedirectInterface $redirect)
 {
     $this->outputLine('   %s %s <info>=></info> %s <comment>(%d)</comment> - %s', [$prefix, $redirect->getSourceUriPath(), $redirect->getTargetUriPath(), $redirect->getStatusCode(), $redirect->getHost() ?: 'all host']);
 }
 /**
  * Updates affected redirects in order to avoid redundant or circular redirections.
  *
  * @param RedirectInterface $newRedirect
  * @throws Exception if creating the redirect would cause conflicts
  * @return void
  */
 protected function updateDependingRedirects(RedirectInterface $newRedirect)
 {
     /** @var $existingRedirectForSourceUriPath Redirect */
     $existingRedirectForSourceUriPath = $this->redirectRepository->findOneBySourceUriPathAndHost($newRedirect->getSourceUriPath(), $newRedirect->getHost(), false);
     if ($existingRedirectForSourceUriPath !== null) {
         $this->removeAndLog($existingRedirectForSourceUriPath, sprintf('Existing redirect for the source URI path "%s" removed.', $newRedirect->getSourceUriPath()));
         $this->routerCachingService->flushCachesForUriPath($existingRedirectForSourceUriPath->getSourceUriPath());
     }
     /** @var $existingRedirectForTargetUriPath Redirect */
     $existingRedirectForTargetUriPath = $this->redirectRepository->findOneBySourceUriPathAndHost($newRedirect->getTargetUriPath(), $newRedirect->getHost(), false);
     if ($existingRedirectForTargetUriPath !== null) {
         $this->removeAndLog($existingRedirectForTargetUriPath, sprintf('Existing redirect for the target URI path "%s" removed.', $newRedirect->getTargetUriPath()));
         $this->routerCachingService->flushCachesForUriPath($existingRedirectForTargetUriPath->getSourceUriPath());
     }
     $obsoleteRedirectInstances = $this->redirectRepository->findByTargetUriPathAndHost($newRedirect->getSourceUriPath(), $newRedirect->getHost());
     /** @var $obsoleteRedirect Redirect */
     foreach ($obsoleteRedirectInstances as $obsoleteRedirect) {
         if ($obsoleteRedirect->getSourceUriPath() === $newRedirect->getTargetUriPath()) {
             $this->redirectRepository->remove($obsoleteRedirect);
         } else {
             $obsoleteRedirect->setTargetUriPath($newRedirect->getTargetUriPath());
             $this->redirectRepository->update($obsoleteRedirect);
         }
     }
 }
 /**
  * @param RedirectInterface $redirect
  * @return void
  */
 public function incrementHitCount(RedirectInterface $redirect)
 {
     $host = $redirect->getHost();
     /** @var Query $query */
     if ($host === null) {
         $query = $this->entityManager->createQuery('UPDATE Neos\\RedirectHandler\\DatabaseStorage\\Domain\\Model\\Redirect r SET r.hitCounter = r.hitCounter + 1, r.lastHit = CURRENT_TIMESTAMP() WHERE r.sourceUriPath = :sourceUriPath and r.host IS NULL');
     } else {
         $query = $this->entityManager->createQuery('UPDATE Neos\\RedirectHandler\\DatabaseStorage\\Domain\\Model\\Redirect r SET r.hitCounter = r.hitCounter + 1, r.lastHit = CURRENT_TIMESTAMP() WHERE r.sourceUriPath = :sourceUriPath and r.host = :host');
         $query->setParameter('host', $host);
     }
     $query->setParameter('sourceUriPath', $redirect->getSourceUriPath())->execute();
 }