/**
  * This feature is cleaner for redirection.
  * Saves requests to the database if I'm not mistaken.
  * @return $this|null redirect to either the correct page/object or do nothing (In that case, the item exists and we're gonna show it lateron).
  */
 private function needsRedirect()
 {
     /** @var int|string $id */
     $id = $this->getRequest()->param('ID');
     /** @var string $action */
     $action = $this->getRequest()->param('Action');
     /** @var array $handlers */
     $handlers = self::$url_handlers;
     if (isset($handlers[$action]) && $handlers[$action] == 'show' && !($news = $this->getNews())) {
         if ($id && is_numeric($id)) {
             /** @var News $redirect */
             $redirect = $this->Newsitems()->byId($id);
             $this->redirect($redirect->Link(), 301);
         } else {
             /** @var Renamed $renamed */
             $renamed = Renamed::get()->filter(array('OldLink' => $id));
             if ($renamed->count() > 0) {
                 $this->redirect($renamed->First()->News()->Link(), 301);
             } else {
                 $this->redirect($this->Link(), 404);
             }
         }
     } elseif ($action === 'latest') {
         /** @var News $item */
         $item = News::get()->filter(array('Live' => true))->first();
         $this->redirect($item->Link(), 302);
     }
 }
 /**
  * Setup the URLSegment for this item and create a Renamed Object if it's a rename-action.
  */
 private function setURLValue()
 {
     if (!$this->URLSegment || $this->isChanged('Title') && !$this->isChanged('URLSegment')) {
         if ($this->ID > 0) {
             $Renamed = new Renamed();
             $Renamed->OldLink = $this->URLSegment;
             $Renamed->NewsID = $this->ID;
             $Renamed->write();
         }
         $this->URLSegment = singleton('SiteTree')->generateURLSegment($this->Title);
         if (strpos($this->URLSegment, 'page-') === false) {
             $nr = 1;
             $URLSegment = $this->URLSegment;
             while ($this->LookForExistingURLSegment($URLSegment)) {
                 $URLSegment = $this->URLSegment . '-' . $nr++;
             }
             $this->URLSegment = $URLSegment;
         }
     }
 }