3 use Friendica\Core\Config;
5 function update_queue_time($id) {
6 logger('queue: requeue item ' . $id);
7 q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d",
8 dbesc(datetime_convert()),
13 function remove_queue_item($id) {
14 logger('queue: remove queue item ' . $id);
15 q("DELETE FROM `queue` WHERE `id` = %d",
21 * @brief Checks if the communication with a given contact had problems recently
23 * @param int $cid Contact id
25 * @return bool The communication with this contact has currently problems
27 function was_recently_delayed($cid) {
30 // Are there queue entries that were recently added?
31 $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d
32 AND `last` > UTC_TIMESTAMP() - INTERVAL 15 MINUTE LIMIT 1",
36 $was_delayed = dbm::is_result($r);
38 // We set "term-date" to a current date if the communication has problems.
39 // If the communication works again we reset this value.
41 $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` <= '1000-01-01' LIMIT 1",
44 $was_delayed = !dbm::is_result($r);
51 function add_to_queue($cid,$network,$msg,$batch = false) {
53 $max_queue = Config::get('system','max_contact_queue');
58 $batch_queue = Config::get('system','max_batch_queue');
59 if ($batch_queue < 1) {
63 $r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
64 WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
67 if (dbm::is_result($r)) {
68 if ($batch && ($r[0]['total'] > $batch_queue)) {
69 logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
71 } elseif ((! $batch) && ($r[0]['total'] > $max_queue)) {
72 logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
77 q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
78 VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
81 dbesc(datetime_convert()),
82 dbesc(datetime_convert()),
84 intval(($batch) ? 1: 0)