]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Subscription.php
Event plugin uses saveObjectFromActivity for RSVP
[quix0rs-gnu-social.git] / classes / Subscription.php
index 5c5101ad1d1bb430ed0493037782b0ed4c0c87b9..314a597f55e681e08a55e1adc26a25327384c523 100644 (file)
@@ -94,10 +94,14 @@ 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) {
-                $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 = self::saveNew($subscriber, $other);
                 $sub->notify();
 
                 self::blow('user:notices_with_friends:%d', $subscriber->id);
@@ -124,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));
             }
         }
@@ -132,16 +136,26 @@ 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) {
+            return self::getSubscription($subscriber, $other);
+        }
+        return $sub;
+    }
+
     /**
      * Low-level subscription save.
      * Outside callers should use Subscription::start()
      */
-    protected function saveNew($subscriber_id, $other_id)
+    protected static function saveNew(Profile $subscriber, Profile $other)
     {
         $sub = new Subscription();
 
-        $sub->subscriber = $subscriber_id;
-        $sub->subscribed = $other_id;
+        $sub->subscriber = $subscriber->getID();
+        $sub->subscribed = $other->getID();
         $sub->jabber     = 1;
         $sub->sms        = 1;
         $sub->created    = common_sql_now();