3 if (!defined('GNUSOCIAL')) { exit(1); }
6 * Table Definition for subscription_queue
9 class Subscription_queue extends Managed_DataObject
11 public $__table = 'subscription_queue'; // table name
16 public static function schemaDef()
19 'description' => 'Holder for subscription requests awaiting moderation.',
21 'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
22 'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile being subscribed to'),
23 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
25 'primary key' => array('subscriber', 'subscribed'),
27 'subscription_queue_subscriber_created_idx' => array('subscriber', 'created'),
28 'subscription_queue_subscribed_created_idx' => array('subscribed', 'created'),
30 'foreign keys' => array(
31 'subscription_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
32 'subscription_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
37 public static function saveNew(Profile $subscriber, Profile $subscribed)
39 if (self::exists($subscriber, $subscribed)) {
40 throw new AlreadyFulfilledException(_('This subscription request is already in progress.'));
42 $rq = new Subscription_queue();
43 $rq->subscriber = $subscriber->id;
44 $rq->subscribed = $subscribed->id;
45 $rq->created = common_sql_now();
50 static function exists(Profile $subscriber, Profile $other)
52 $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->getID(),
53 'subscribed' => $other->getID()));
54 return ($sub instanceof Subscription_queue);
57 static function getSubQueue(Profile $subscriber, Profile $other)
59 // This is essentially a pkeyGet but we have an object to return in NoResultException
60 $sub = new Subscription_queue();
61 $sub->subscriber = $subscriber->id;
62 $sub->subscribed = $other->id;
63 if (!$sub->find(true)) {
64 throw new NoResultException($sub);
70 * Complete a pending subscription, as we've got approval of some sort.
72 * @return Subscription
74 public function complete()
76 $subscriber = Profile::getKV('id', $this->subscriber);
77 $subscribed = Profile::getKV('id', $this->subscribed);
79 $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE);
81 } catch (AlreadyFulfilledException $e) {
82 common_debug('Tried to start a subscription which already existed.');
88 * Cancel an outstanding subscription request to the other profile.
90 public function abort()
92 $subscriber = Profile::getKV('id', $this->subscriber);
93 $subscribed = Profile::getKV('id', $this->subscribed);
94 if (Event::handle('StartCancelSubscription', array($subscriber, $subscribed))) {
96 Event::handle('EndCancelSubscription', array($subscriber, $subscribed));
101 * Send notifications via email etc to group administrators about
102 * this exciting new pending moderation queue item!
104 public function notify()
106 $other = Profile::getKV('id', $this->subscriber);
107 $listenee = User::getKV('id', $this->subscribed);
108 mail_subscribe_pending_notify_profile($listenee, $other);