]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Subscription class gets exception throwing getSubscription function
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 17 Feb 2015 16:15:47 +0000 (17:15 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 17 Feb 2015 16:15:47 +0000 (17:15 +0100)
classes/Subscription.php

index 4d7eb524dcf8d89da61e4ba15d9a2bac39d7b7cc..cd9ae3cce519ec0ab6079747c305cd5bf230ba73 100644 (file)
@@ -232,9 +232,25 @@ class Subscription extends Managed_DataObject
 
     static function exists(Profile $subscriber, Profile $other)
     {
-        $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
-                                           'subscribed' => $other->id));
-        return ($sub instanceof Subscription);
+        try {
+            $sub = self::getSubscription($subscriber, $other);
+        } catch (NoResultException $e) {
+            return false;
+        }
+
+        return true;
+    }
+
+    static function getSubscription(Profile $subscriber, Profile $other)
+    {
+        // This is essentially a pkeyGet but we have an object to return in NoResultException
+        $sub = new Subscription();
+        $sub->subscriber = $subscriber->id;
+        $sub->subscribed = $other->id;
+        if (!$sub->find(true)) {
+            throw new NoResultException($sub);
+        }
+        return $sub;
     }
 
     function asActivity()