+ public function exists(Profile $subscriber, Profile $other)
+ {
+ $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
+ 'subscribed' => $other->id));
+ 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;
+ }
+
+ /**
+ * Complete a pending subscription, as we've got approval of some sort.
+ *
+ * @return Subscription
+ */
+ public function complete()
+ {
+ $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;
+ }
+
+ /**
+ * Cancel an outstanding subscription request to the other profile.
+ */
+ public function abort()
+ {
+ $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));
+ }
+ }
+