From adba38ce20714fcb5c41b877650a3d40701b6a9c Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 13 Jan 2016 21:19:20 +0100 Subject: [PATCH] Deleted_notice is pluginified, don't call directly from core --- actions/apistatusesshow.php | 17 +++++++++----- actions/shownotice.php | 22 ++++++++++--------- .../ActivityModerationPlugin.php | 12 ++++++++++ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/actions/apistatusesshow.php b/actions/apistatusesshow.php index 70b9a9c27a..030f8566bf 100644 --- a/actions/apistatusesshow.php +++ b/actions/apistatusesshow.php @@ -74,16 +74,21 @@ class ApiStatusesShowAction extends ApiPrivateAuthAction $this->notice_id = (int)$this->trimmed('id'); - $this->notice = Notice::getKV('id', $this->notice_id); - if (!$this->notice instanceof Notice) { - $deleted = Deleted_notice::getKV('id', $this->notice_id); - if ($deleted instanceof Deleted_notice) { + $this->notice = null; + try { + $this->notice = Notice::getByID($this->notice_id); + } catch (NoResultException $e) { + // No such notice was found, maybe it was deleted? + $deleted = null; + Event::handle('IsNoticeDeleted', array($this->notice_id, &$deleted)); + if ($deleted === true) { // TRANS: Client error displayed trying to show a deleted notice. - $this->clientError(_('Notice deleted.'), 410); + throw new ClientException(_('Notice deleted.'), 410); } // TRANS: Client error displayed trying to show a non-existing notice. - $this->clientError(_('No such notice.'), 404); + throw new ClientException(_('No such notice.'), 404); } + if (!$this->notice->inScope($this->scoped)) { // TRANS: Client exception thrown when trying a view a notice the user has no access to. throw new ClientException(_('Access restricted.'), 403); diff --git a/actions/shownotice.php b/actions/shownotice.php index 23386868dd..64cf38afa7 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -113,20 +113,22 @@ class ShownoticeAction extends ManagedAction { $id = $this->arg('notice'); - $notice = Notice::getKV('id', $id); - if ($notice instanceof Notice) { + $notice = null; + try { + $notice = Notice::getByID($id); // Alright, got it! return $notice; - } - - // Did we use to have it, and it got deleted? - $deleted = Deleted_notice::getKV('id', $id); - if ($deleted instanceof Deleted_notice) { - // TRANS: Client error displayed trying to show a deleted notice. - $this->clientError(_('Notice deleted.'), 410); + } catch (NoResultException $e) { + // Hm, not found. + $deleted = null; + Event::handle('IsNoticeDeleted', array($id, &$deleted)); + if ($deleted === true) { + // TRANS: Client error displayed trying to show a deleted notice. + throw new ClientException(_('Notice deleted.'), 410); + } } // TRANS: Client error displayed trying to show a non-existing notice. - $this->clientError(_('No such notice.'), 404); + throw new ClientException(_('No such notice.'), 404); } /** diff --git a/plugins/ActivityModeration/ActivityModerationPlugin.php b/plugins/ActivityModeration/ActivityModerationPlugin.php index 526b8b1875..208a05449d 100644 --- a/plugins/ActivityModeration/ActivityModerationPlugin.php +++ b/plugins/ActivityModeration/ActivityModerationPlugin.php @@ -46,6 +46,18 @@ class ActivityModerationPlugin extends ActivityVerbHandlerPlugin return false; } + public function onIsNoticeDeleted($id, &$deleted) + { + try { + $found = Deleted_notice::getByID($id); + $deleted = ($found instanceof Deleted_notice); + } catch (NoResultException $e) { + $deleted = false; + } + // return true (continue event) if $deleted is false, return false (stop event) if deleted notice was found + return !$deleted; + } + protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped) { // FIXME: switch based on action type