]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Favorite/classes/Fave.php
Merge branch 'nightly' of gitorious.org:social/mainline into nightly
[quix0rs-gnu-social.git] / plugins / Favorite / classes / Fave.php
index 094b65feaa94fd19b38f6b5dd12e6af5b48ebd10..48ed3ba93bcb3d4a8accae430e4c054e2a0ef9f2 100644 (file)
@@ -48,6 +48,11 @@ class Fave extends Managed_DataObject
      * @throws Exception on failure
      */
     static function addNew(Profile $actor, Notice $target) {
+        if (self::existsForProfile($target, $actor)) {
+            // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
+            throw new AlreadyFulfilledException(_('You have already favorited this!'));
+        }
+
         $act = new Activity();
         $act->type    = ActivityObject::ACTIVITY;
         $act->verb    = ActivityVerb::FAVORITE;
@@ -74,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()
     {