Improve ShownoticeAction remote redirect code

This commit is contained in:
Mikael Nordfeldth 2014-04-19 22:13:48 +02:00
parent 454a9bc1c4
commit 132be99506
2 changed files with 8 additions and 12 deletions

View File

@ -218,17 +218,13 @@ class ShownoticeAction extends Action
$this->showAjax(); $this->showAjax();
} else { } else {
if ($this->notice->is_local == Notice::REMOTE) { if ($this->notice->is_local == Notice::REMOTE) {
if (!empty($this->notice->url)) { try {
$target = $this->notice->url; $target = $this->notice->getUrl()
} else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) { if ($target != $this->selfUrl()) {
// Old OMB posts saved the remote URL only into the URI field. common_redirect($target, 301);
$target = $this->notice->uri; }
} else { } catch (InvalidUrlException $e) {
// Shouldn't happen. common_debug('ShownoticeAction could not redirect to remote notice with id='.$this->notice->id . '. Falling back to showPage().');
$target = false;
}
if ($target && $target != $this->selfUrl()) {
common_redirect($target, 301);
} }
} }
$this->showPage(); $this->showPage();

View File

@ -224,7 +224,7 @@ class Notice extends Managed_DataObject
return $this->uri; return $this->uri;
default: default:
common_debug('No URL available for notice: id='.$this->id); common_debug('No URL available for notice: id='.$this->id);
throw new ServerException('No URL available for notice.'); throw new InvalidUrlException($this->url);
} }
} }