Subscription class gets exception throwing getSubscription function

This commit is contained in:
Mikael Nordfeldth 2015-02-17 17:15:47 +01:00
parent 901a825b61
commit 61aa71ed34

View 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()