]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Subscription_queue.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / classes / Subscription_queue.php
index 19cd71c6a8523a0c0b61bbd86eedcae2708783b5..405eca93fd0f7309ffdd6c5e78b1375c2918120e 100644 (file)
@@ -1,30 +1,18 @@
 <?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
 /**
  * Table Definition for subscription_queue
  */
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
 
 class Subscription_queue extends Managed_DataObject
 {
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
     public $__table = 'subscription_queue';       // table name
     public $subscriber;
     public $subscribed;
     public $created;
 
-    /* Static get */
-    function staticGet($k,$v=null)
-    { return Memcached_DataObject::staticGet('Subscription_queue',$k,$v); }
-
-    /* Pkey get */
-    function pkeyGet($k)
-    { return Memcached_DataObject::pkeyGet('Subscription_queue',$k); }
-
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-
     public static function schemaDef()
     {
         return array(
@@ -56,11 +44,11 @@ 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);
     }
 
     /**
@@ -70,11 +58,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 +74,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 +88,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);
     }
 }