From: Mikael Nordfeldth Date: Wed, 13 Jan 2016 20:19:20 +0000 (+0100) Subject: Deleted_notice is pluginified, don't call directly from core X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=adba38ce20714fcb5c41b877650a3d40701b6a9c;p=quix0rs-gnu-social.git Deleted_notice is pluginified, don't call directly from core --- 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