X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FSubscription_queue.php;h=878fcf5796968028b7464b441a00aeb9e1eaf2a2;hb=dcfcceb6f2d4d35eb2a0d19f96aefb38c4b37533;hp=19cd71c6a8523a0c0b61bbd86eedcae2708783b5;hpb=1e73ba00bdd37f46415eb45b1b904dc894fb801c;p=quix0rs-gnu-social.git diff --git a/classes/Subscription_queue.php b/classes/Subscription_queue.php index 19cd71c6a8..878fcf5796 100644 --- a/classes/Subscription_queue.php +++ b/classes/Subscription_queue.php @@ -1,30 +1,18 @@ subscriber = $subscriber->id; $rq->subscribed = $subscribed->id; @@ -56,11 +47,23 @@ class Subscription_queue extends Managed_DataObject return $rq; } - function exists($subscriber, $other) + public function exists(Profile $subscriber, Profile $other) { $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id, 'subscribed' => $other->id)); - return (empty($sub)) ? false : true; + return ($sub instanceof Subscription_queue); + } + + static function getSubQueue(Profile $subscriber, Profile $other) + { + // This is essentially a pkeyGet but we have an object to return in NoResultException + $sub = new Subscription_queue(); + $sub->subscriber = $subscriber->id; + $sub->subscribed = $other->id; + if (!$sub->find(true)) { + throw new NoResultException($sub); + } + return $sub; } /** @@ -70,11 +73,13 @@ class Subscription_queue extends Managed_DataObject */ public function complete() { - $subscriber = Profile::staticGet('id', $this->subscriber); - $subscribed = Profile::staticGet('id', $this->subscribed); - $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE); - if ($sub) { + $subscriber = Profile::getKV('id', $this->subscriber); + $subscribed = Profile::getKV('id', $this->subscribed); + try { + $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE); $this->delete(); + } catch (AlreadyFulfilledException $e) { + common_debug('Tried to start a subscription which already existed.'); } return $sub; } @@ -84,8 +89,8 @@ class Subscription_queue extends Managed_DataObject */ public function abort() { - $subscriber = Profile::staticGet('id', $this->subscriber); - $subscribed = Profile::staticGet('id', $this->subscribed); + $subscriber = Profile::getKV('id', $this->subscriber); + $subscribed = Profile::getKV('id', $this->subscribed); if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) { $this->delete(); Event::handle('EndCancelSubscription', array($subscriber, $subscribed)); @@ -98,8 +103,8 @@ class Subscription_queue extends Managed_DataObject */ public function notify() { - $other = Profile::staticGet('id', $this->subscriber); - $listenee = User::staticGet('id', $this->subscribed); + $other = Profile::getKV('id', $this->subscriber); + $listenee = User::getKV('id', $this->subscribed); mail_subscribe_pending_notify_profile($listenee, $other); } }