]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Favorite/classes/Fave.php
FavoritePlugin is now an "ActivityVerbHandlerPlugin"
[quix0rs-gnu-social.git] / plugins / Favorite / classes / Fave.php
index ba0d04ba25f9a9ecaaea8ca35ffab4e6ec466039..48ed3ba93bcb3d4a8accae430e4c054e2a0ef9f2 100644 (file)
@@ -79,6 +79,27 @@ class Fave extends Managed_DataObject
         return $stored;
     }
 
+    public function removeEntry(Profile $actor, Notice $target)
+    {
+        $fave            = new Fave();
+        $fave->user_id   = $actor->getID();
+        $fave->notice_id = $target->getID();
+        if (!$fave->find(true)) {
+            // TRANS: Client error displayed when trying to remove a 'favor' when there is none in the first place.
+            throw new AlreadyFulfilledException(_('This is already not favorited.'));
+        }
+
+        $result = $fave->delete();
+        if ($result === false) {
+            common_log_db_error($fave, 'DELETE', __FILE__);
+            // TRANS: Server error displayed when removing a favorite from the database fails.
+            throw new ServerException(_('Could not delete favorite.'));
+        }
+
+        Fave::blowCacheForProfileId($actor->getID());
+        Fave::blowCacheForNoticeId($target->getID());
+    }
+
     // exception throwing takeover!
     public function insert()
     {