X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItemDeliveryData.php;h=a26c80b1cb1f356a18f3a01f9b70f887362995ae;hb=7b7132971a64a92a685a5fd860fe4709dce1765a;hp=e3be073e8e86bba0b53a594ca7709766405a0f75;hpb=1696ad962ea4fdae16a6bff29a6a98ee523108e5;p=friendica.git diff --git a/src/Model/ItemDeliveryData.php b/src/Model/ItemDeliveryData.php index e3be073e8e..a26c80b1cb 100644 --- a/src/Model/ItemDeliveryData.php +++ b/src/Model/ItemDeliveryData.php @@ -1,24 +1,51 @@ . + * */ namespace Friendica\Model; use Friendica\Database\DBA; +use \BadMethodCallException; class ItemDeliveryData { - const FIELD_LIST = [ + const LEGACY_FIELD_LIST = [ // Legacy fields moved from item table 'postopts', 'inform', + ]; + + const FIELD_LIST = [ // 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; + const MAIL = 6; + /** * Extract delivery data from the provided item fields * @@ -28,7 +55,7 @@ class ItemDeliveryData public static function extractFields(array &$fields) { $delivery_data = []; - foreach (ItemDeliveryData::FIELD_LIST as $key => $field) { + foreach (array_merge(ItemDeliveryData::FIELD_LIST, ItemDeliveryData::LEGACY_FIELD_LIST) as $key => $field) { if (is_int($key) && isset($fields[$field])) { // Legacy field moved from item table $delivery_data[$field] = $fields[$field]; @@ -49,11 +76,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); } /** @@ -62,11 +138,12 @@ class ItemDeliveryData * @param integer $item_id * @param array $fields * @return bool + * @throws \Exception */ 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; @@ -82,11 +159,12 @@ class ItemDeliveryData * @param integer $item_id * @param array $fields * @return bool + * @throws \Exception */ 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)) { @@ -102,11 +180,12 @@ class ItemDeliveryData * * @param integer $item_id * @return bool + * @throws \Exception */ 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]);