]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Deleted_notice is pluginified, don't call directly from core
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 13 Jan 2016 20:19:20 +0000 (21:19 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 13 Jan 2016 20:29:23 +0000 (21:29 +0100)
actions/apistatusesshow.php
actions/shownotice.php
plugins/ActivityModeration/ActivityModerationPlugin.php

index 70b9a9c27a49427fc3ab6eed4ed5cea7bb92c9d5..030f8566bf1c6dc095b4e253099590c3eac883fd 100644 (file)
@@ -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);
index 23386868ddbc1b042b3151b29340b952c86cf35c..64cf38afa7960d59acd38faa00569918b3acd91c 100644 (file)
@@ -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);
     }
 
     /**
index 526b8b1875c45b0207d5294b20257f80983ef4f8..208a05449df1eb4d3797c3b8413291783b7e23b5 100644 (file)
@@ -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