]> git.mxchange.org Git - friendica.git/blob - include/queue_fn.php
reverted change (which duplicated above query), thanks to @annano to point this out...
[friendica.git] / include / queue_fn.php
1 <?php
2
3 function update_queue_time($id) {
4         logger('queue: requeue item ' . $id);
5         q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d",
6                 dbesc(datetime_convert()),
7                 intval($id)
8         );
9 }
10
11 function remove_queue_item($id) {
12         logger('queue: remove queue item ' . $id);
13         q("DELETE FROM `queue` WHERE `id` = %d",
14                 intval($id)
15         );
16 }
17
18 /**
19  * @brief Checks if the communication with a given contact had problems recently
20  *
21  * @param int $cid Contact id
22  *
23  * @return bool The communication with this contact has currently problems
24  */
25 function was_recently_delayed($cid) {
26
27         $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d 
28                 and last > UTC_TIMESTAMP() - interval 15 minute limit 1",
29                 intval($cid)
30         );
31         if (dbm::is_result($r))
32                 return true;
33
34         $r = q("select `term-date` from contact where id = %d and `term-date` != '' and `term-date` != '0000-00-00 00:00:00' limit 1",
35                 intval($cid)
36         );
37
38         return (dbm::is_result($r));
39 }
40
41
42 function add_to_queue($cid,$network,$msg,$batch = false) {
43
44         $max_queue = get_config('system','max_contact_queue');
45         if($max_queue < 1)
46                 $max_queue = 500;
47
48         $batch_queue = get_config('system','max_batch_queue');
49         if($batch_queue < 1)
50                 $batch_queue = 1000;
51
52         $r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` 
53                 WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
54                 intval($cid)
55         );
56         if (dbm::is_result($r)) {
57                 if($batch &&  ($r[0]['total'] > $batch_queue)) {
58                         logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
59                         return;
60                 }
61                 elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
62                         logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
63                         return;
64                 }
65         }
66
67         q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
68                 VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
69                 intval($cid),
70                 dbesc($network),
71                 dbesc(datetime_convert()),
72                 dbesc(datetime_convert()),
73                 dbesc($msg),
74                 intval(($batch) ? 1: 0)
75         );
76
77 }