From 132be9950662ce0d5a1e859a766232cd7fdcb0e1 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 19 Apr 2014 22:13:48 +0200 Subject: [PATCH] Improve ShownoticeAction remote redirect code --- actions/shownotice.php | 18 +++++++----------- classes/Notice.php | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/actions/shownotice.php b/actions/shownotice.php index d86e98080b..b72f39513e 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -218,17 +218,13 @@ 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()) { - common_redirect($target, 301); + 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(); diff --git a/classes/Notice.php b/classes/Notice.php index 99d44b6cff..e46ed227a1 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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); } } -- 2.39.5