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

View File

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