]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/ItemDeliveryData.php
Type hints
[friendica.git] / src / Model / ItemDeliveryData.php
index 1cd9c4f448acb897a8817bf507dfe05f12a6fdc1..7c64427eff7571ebb0608e833b37d63f62890d0c 100644 (file)
@@ -7,6 +7,7 @@
 namespace Friendica\Model;
 
 use Friendica\Database\DBA;
+use \BadMethodCallException;
 
 class ItemDeliveryData
 {
@@ -20,8 +21,15 @@ class ItemDeliveryData
                // New delivery fields with virtual field name in item fields
                'queue_count' => 'delivery_queue_count',
                'queue_done'  => 'delivery_queue_done',
+               'queue_failed'  => 'delivery_queue_failed',
        ];
 
+       const ACTIVITYPUB = 1;
+       const DFRN = 2;
+       const LEGACY_DFRN = 3;
+       const DIASPORA = 4;
+       const OSTATUS = 5;
+
        /**
         * Extract delivery data from the provided item fields
         *
@@ -52,12 +60,60 @@ class ItemDeliveryData
         * Avoids racing condition between multiple delivery threads.
         *
         * @param integer $item_id
+        * @param integer $protocol
+        * @return bool
+        * @throws \Exception
+        */
+       public static function incrementQueueDone($item_id, $protocol = 0)
+       {
+               $sql = '';
+
+               switch ($protocol) {
+                       case self::ACTIVITYPUB:
+                               $sql = ", `activitypub` = `activitypub` + 1";
+                               break;
+                       case self::DFRN:
+                               $sql = ", `dfrn` = `dfrn` + 1";
+                               break;
+                       case self::LEGACY_DFRN:
+                               $sql = ", `legacy_dfrn` = `legacy_dfrn` + 1";
+                               break;
+                       case self::DIASPORA:
+                               $sql = ", `diaspora` = `diaspora` + 1";
+                               break;
+                       case self::OSTATUS:
+                               $sql = ", `ostatus` = `ostatus` + 1";
+                               break;
+               }
+
+               return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `iid` = ?', $item_id);
+       }
+
+       /**
+        * Increments the queue_failed for the given item ID.
+        *
+        * Avoids racing condition between multiple delivery threads.
+        *
+        * @param integer $item_id
+        * @return bool
+        * @throws \Exception
+        */
+       public static function incrementQueueFailed($item_id)
+       {
+               return DBA::e('UPDATE `item-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `iid` = ?', $item_id);
+       }
+
+       /**
+        * Increments the queue_count for the given item ID.
+        *
+        * @param integer $item_id
+        * @param integer $increment
         * @return bool
         * @throws \Exception
         */
-       public static function incrementQueueDone($item_id)
+       public static function incrementQueueCount(int $item_id, int $increment = 1)
        {
-               return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1 WHERE `iid` = ?', $item_id);
+               return DBA::e('UPDATE `item-delivery-data` SET `queue_count` = `queue_count` + ? WHERE `iid` = ?', $increment, $item_id);
        }
 
        /**
@@ -71,7 +127,7 @@ class ItemDeliveryData
        public static function insert($item_id, array $fields)
        {
                if (empty($item_id)) {
-                       throw new \BadMethodCallException('Empty item_id');
+                       throw new BadMethodCallException('Empty item_id');
                }
 
                $fields['iid'] = $item_id;
@@ -92,7 +148,7 @@ class ItemDeliveryData
        public static function update($item_id, array $fields)
        {
                if (empty($item_id)) {
-                       throw new \BadMethodCallException('Empty item_id');
+                       throw new BadMethodCallException('Empty item_id');
                }
 
                if (empty($fields)) {
@@ -113,7 +169,7 @@ class ItemDeliveryData
        public static function delete($item_id)
        {
                if (empty($item_id)) {
-                       throw new \BadMethodCallException('Empty item_id');
+                       throw new BadMethodCallException('Empty item_id');
                }
 
                return DBA::delete('item-delivery-data', ['iid' => $item_id]);