]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Try the whole Salmon action for AlreadyFulfilledException
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 2 Jun 2014 11:44:08 +0000 (13:44 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 2 Jun 2014 11:57:30 +0000 (13:57 +0200)
If we have already fulfilled the action, we don't have to send an error back.

plugins/OStatus/actions/usersalmon.php
plugins/OStatus/lib/salmonaction.php

index b0b7cd1e904383d57a656db5cb937fe323697707..93e768d8e7b40d4f38f9c81de714b1dc4da1ecf1 100644 (file)
@@ -113,8 +113,7 @@ class UsersalmonAction extends SalmonAction
         $oprofile = $this->ensureProfile();
         if ($oprofile instanceof Ostatus_profile) {
             common_log(LOG_INFO, sprintf('Setting up subscription from remote %s to local %s', $oprofile->getUri(), $this->target->getNickname()));
-            Subscription::start($oprofile->localProfile(),
-                                $this->target);
+            Subscription::start($oprofile->localProfile(), $this->target);
         } else {
             common_log(LOG_INFO, "Can't set up subscription from remote; missing profile.");
         }
@@ -135,8 +134,6 @@ class UsersalmonAction extends SalmonAction
                 Subscription::cancel($oprofile->localProfile(), $this->target);
             } catch (NoProfileException $e) {
                 common_debug('Could not find profile for Subscription: '.$e->getMessage());
-            } catch (AlreadyFulfilledException $e) {
-                common_debug('Subscription did not exist, so there was nothing to cancel');
             }
         } else {
             common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
@@ -158,7 +155,7 @@ class UsersalmonAction extends SalmonAction
 
         if ($old instanceof Fave) {
             // TRANS: Client exception.
-            throw new ClientException(_m('This is already a favorite.'));
+            throw new AlreadyFulfilledException(_m('This is already a favorite.'));
         }
 
         if (!Fave::addNew($profile, $notice)) {
@@ -180,7 +177,7 @@ class UsersalmonAction extends SalmonAction
                                    'notice_id' => $notice->id));
         if (!$fave instanceof Fave) {
             // TRANS: Client exception.
-            throw new ClientException(_m('Notice was not favorited!'));
+            throw new AlreadyFulfilledException(_m('Notice was not favorited!'));
         }
 
         $fave->delete();
index 6e44ff2eb606bd219a41967b522c0673089a367f..647187f323bbe501d268dc641fd8807a3fa9f917 100644 (file)
@@ -77,50 +77,56 @@ class SalmonAction extends Action
         parent::handle();
 
         common_log(LOG_DEBUG, "Got a " . $this->activity->verb);
-        if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) &&
-            Event::handle('StartHandleSalmon', array($this->activity))) {
-            switch ($this->activity->verb)
-            {
-            case ActivityVerb::POST:
-                $this->handlePost();
-                break;
-            case ActivityVerb::SHARE:
-                $this->handleShare();
-                break;
-            case ActivityVerb::FAVORITE:
-                $this->handleFavorite();
-                break;
-            case ActivityVerb::UNFAVORITE:
-                $this->handleUnfavorite();
-                break;
-            case ActivityVerb::FOLLOW:
-            case ActivityVerb::FRIEND:
-                $this->handleFollow();
-                break;
-            case ActivityVerb::UNFOLLOW:
-                $this->handleUnfollow();
-                break;
-            case ActivityVerb::JOIN:
-                $this->handleJoin();
-                break;
-            case ActivityVerb::LEAVE:
-                $this->handleLeave();
-                break;
-            case ActivityVerb::TAG:
-                $this->handleTag();
-                break;
-            case ActivityVerb::UNTAG:
-                $this->handleUntag();
-                break;
-            case ActivityVerb::UPDATE_PROFILE:
-                $this->handleUpdateProfile();
-                break;
-            default:
-                // TRANS: Client exception.
-                throw new ClientException(_m('Unrecognized activity type.'));
+        try {
+            if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) &&
+                    Event::handle('StartHandleSalmon', array($this->activity))) {
+                switch ($this->activity->verb) {
+                case ActivityVerb::POST:
+                    $this->handlePost();
+                    break;
+                case ActivityVerb::SHARE:
+                    $this->handleShare();
+                    break;
+                case ActivityVerb::FAVORITE:
+                    $this->handleFavorite();
+                    break;
+                case ActivityVerb::UNFAVORITE:
+                    $this->handleUnfavorite();
+                    break;
+                case ActivityVerb::FOLLOW:
+                case ActivityVerb::FRIEND:
+                    $this->handleFollow();
+                    break;
+                case ActivityVerb::UNFOLLOW:
+                    $this->handleUnfollow();
+                    break;
+                case ActivityVerb::JOIN:
+                    $this->handleJoin();
+                    break;
+                case ActivityVerb::LEAVE:
+                    $this->handleLeave();
+                    break;
+                case ActivityVerb::TAG:
+                    $this->handleTag();
+                    break;
+                case ActivityVerb::UNTAG:
+                    $this->handleUntag();
+                    break;
+                case ActivityVerb::UPDATE_PROFILE:
+                    $this->handleUpdateProfile();
+                    break;
+                default:
+                    // TRANS: Client exception.
+                    throw new ClientException(_m('Unrecognized activity type.'));
+                }
+                Event::handle('EndHandleSalmon', array($this->activity));
+                Event::handle('EndHandleSalmonTarget', array($this->activity, $this->target));
             }
-            Event::handle('EndHandleSalmon', array($this->activity));
-            Event::handle('EndHandleSalmonTarget', array($this->activity, $this->target));
+        } catch (AlreadyFulfilledException $e) {
+            // The action's results are already fulfilled. Maybe it was a
+            // duplicate? Maybe someone's database is out of sync?
+            // Let's just accept it and move on.
+            common_log(LOG_INFO, 'Salmon slap carried an event which had already been fulfilled.');
         }
     }