]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Subscription_queue::start does not mean Subscription exists
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 4 Mar 2015 10:49:54 +0000 (11:49 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 4 Mar 2015 10:49:54 +0000 (11:49 +0100)
classes/Subscription.php
classes/Subscription_queue.php

index ec9ae518415dc9f347e194742f5356821b51e7e1..6601bcd6fc10ce0b0678b17e5fd3392dc653b09c 100644 (file)
@@ -94,9 +94,12 @@ class Subscription extends Managed_DataObject
         if (Event::handle('StartSubscribe', array($subscriber, $other))) {
             $otherUser = User::getKV('id', $other->id);
             if ($otherUser instanceof User && $otherUser->subscribe_policy == User::SUBSCRIBE_POLICY_MODERATE && !$force) {
-                // Will throw an AlreadyFulfilledException if this queue item already exists.
-                $sub = Subscription_queue::saveNew($subscriber, $other);
-                $sub->notify();
+                try {
+                    $sub = Subscription_queue::saveNew($subscriber, $other);
+                    $sub->notify();
+                } catch (AlreadyFulfilledException $e) {
+                    $sub = Subscription_queue::getSubQueue($subscriber, $other);
+                }
             } else {
                 $sub = self::saveNew($subscriber->id, $other->id);
                 $sub->notify();
@@ -125,7 +128,7 @@ class Subscription extends Managed_DataObject
                 }
             }
 
-            if ($sub instanceof Subscription) { // i.e. not SubscriptionQueue
+            if ($sub instanceof Subscription) { // i.e. not Subscription_queue
                 Event::handle('EndSubscribe', array($subscriber, $other));
             }
         }
@@ -138,7 +141,6 @@ class Subscription extends Managed_DataObject
         try {
             $sub = self::start($subscriber, $other, $force);
         } catch (AlreadyFulfilledException $e) {
-            // Nothing to see here, move along...
             return self::getSubscription($subscriber, $other);
         }
         return $sub;
index 02cc72f1f24c82b32e6f3085b55c4a7c81cebe60..878fcf5796968028b7464b441a00aeb9e1eaf2a2 100644 (file)
@@ -54,6 +54,18 @@ class Subscription_queue extends Managed_DataObject
         return ($sub instanceof Subscription_queue);
     }
 
+    static function getSubQueue(Profile $subscriber, Profile $other)
+    {
+        // This is essentially a pkeyGet but we have an object to return in NoResultException
+        $sub = new Subscription_queue();
+        $sub->subscriber = $subscriber->id;
+        $sub->subscribed = $other->id;
+        if (!$sub->find(true)) {
+            throw new NoResultException($sub);
+        }
+        return $sub;
+    }
+
     /**
      * Complete a pending subscription, as we've got approval of some sort.
      *