]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Subscription_queue.php
Return dynamically generated URLs for thumbnails for all locally stored entries
[quix0rs-gnu-social.git] / classes / Subscription_queue.php
index ea0e906d43fca01c1208eeafc1508fc556d135ab..a60293e2158e9bf8b42ff6f01ff079b1a9056c1b 100644 (file)
@@ -1,22 +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;
 
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-
     public static function schemaDef()
     {
         return array(
@@ -40,6 +36,9 @@ class Subscription_queue extends Managed_DataObject
 
     public static function saveNew(Profile $subscriber, Profile $subscribed)
     {
+        if (self::exists($subscriber, $subscribed)) {
+            throw new AlreadyFulfilledException(_('This subscription request is already in progress.'));
+        }
         $rq = new Subscription_queue();
         $rq->subscriber = $subscriber->id;
         $rq->subscribed = $subscribed->id;
@@ -48,11 +47,23 @@ class Subscription_queue extends Managed_DataObject
         return $rq;
     }
 
-    function exists($subscriber, $other)
+    static function exists(Profile $subscriber, Profile $other)
     {
-        $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->id,
-                                                 'subscribed' => $other->id));
-        return (empty($sub)) ? false : true;
+        $sub = Subscription_queue::pkeyGet(array('subscriber' => $subscriber->getID(),
+                                                 'subscribed' => $other->getID()));
+        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;
     }
 
     /**
@@ -64,9 +75,11 @@ class Subscription_queue extends Managed_DataObject
     {
         $subscriber = Profile::getKV('id', $this->subscriber);
         $subscribed = Profile::getKV('id', $this->subscribed);
-        $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE);
-        if ($sub) {
+        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;
     }