From 61aa71ed34d944d6c4005fdeb33c2128d51eed9d Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 17 Feb 2015 17:15:47 +0100 Subject: [PATCH] Subscription class gets exception throwing getSubscription function --- classes/Subscription.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/classes/Subscription.php b/classes/Subscription.php index 4d7eb524dc..cd9ae3cce5 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -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()