4 * @file src/Model/ItemDeliveryData.php
7 namespace Friendica\Model;
9 use Friendica\Database\DBA;
11 class ItemDeliveryData
13 const LEGACY_FIELD_LIST = [
14 // Legacy fields moved from item table
20 // New delivery fields with virtual field name in item fields
21 'queue_count' => 'delivery_queue_count',
22 'queue_done' => 'delivery_queue_done',
26 * Extract delivery data from the provided item fields
28 * @param array $fields
31 public static function extractFields(array &$fields)
34 foreach (array_merge(ItemDeliveryData::FIELD_LIST, ItemDeliveryData::LEGACY_FIELD_LIST) as $key => $field) {
35 if (is_int($key) && isset($fields[$field])) {
36 // Legacy field moved from item table
37 $delivery_data[$field] = $fields[$field];
38 $fields[$field] = null;
39 } elseif (isset($fields[$field])) {
40 // New delivery field with virtual field name in item fields
41 $delivery_data[$key] = $fields[$field];
42 unset($fields[$field]);
46 return $delivery_data;
50 * Increments the queue_done for the given item ID.
52 * Avoids racing condition between multiple delivery threads.
54 * @param integer $item_id
58 public static function incrementQueueDone($item_id)
60 return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1 WHERE `iid` = ?', $item_id);
64 * Insert a new item delivery data entry
66 * @param integer $item_id
67 * @param array $fields
71 public static function insert($item_id, array $fields)
73 if (empty($item_id)) {
74 throw new \BadMethodCallException('Empty item_id');
77 $fields['iid'] = $item_id;
79 return DBA::insert('item-delivery-data', $fields);
83 * Update/Insert item delivery data
85 * If you want to update queue_done, please use incrementQueueDone instead.
87 * @param integer $item_id
88 * @param array $fields
92 public static function update($item_id, array $fields)
94 if (empty($item_id)) {
95 throw new \BadMethodCallException('Empty item_id');
99 // Nothing to do, update successful
103 return DBA::update('item-delivery-data', $fields, ['iid' => $item_id], true);
107 * Delete item delivery data
109 * @param integer $item_id
113 public static function delete($item_id)
115 if (empty($item_id)) {
116 throw new \BadMethodCallException('Empty item_id');
119 return DBA::delete('item-delivery-data', ['iid' => $item_id]);