]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Subscription.php
Subscription::ensureStart skips AlreadyFulfilledException
[quix0rs-gnu-social.git] / classes / Subscription.php
index 5c5101ad1d1bb430ed0493037782b0ed4c0c87b9..ec9ae518415dc9f347e194742f5356821b51e7e1 100644 (file)
@@ -94,6 +94,7 @@ 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();
             } else {
@@ -132,6 +133,17 @@ class Subscription extends Managed_DataObject
         return $sub;
     }
 
+    static function ensureStart(Profile $subscriber, Profile $other, $force=false)
+    {
+        try {
+            $sub = self::start($subscriber, $other, $force);
+        } catch (AlreadyFulfilledException $e) {
+            // Nothing to see here, move along...
+            return self::getSubscription($subscriber, $other);
+        }
+        return $sub;
+    }
+
     /**
      * Low-level subscription save.
      * Outside callers should use Subscription::start()