]> git.mxchange.org Git - friendica.git/blob - include/queue_fn.php
scrape_dfrn now scrapes the address as well.
[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 function was_recently_delayed($cid) {
19
20         $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d 
21                 and last > UTC_TIMESTAMP() - interval 15 minute limit 1",
22                 intval($cid)
23         );
24         if(count($r))
25                 return true;
26
27         $r = q("select `term-date` from contact where id = %d and `term-date` != '' and `term-date` != '0000-00-00 00:00:00' limit 1",
28                 intval($cid)
29         );
30         if(count($r))
31                 return true;
32
33         return false;
34 }
35
36
37 function add_to_queue($cid,$network,$msg,$batch = false) {
38
39         $max_queue = get_config('system','max_contact_queue');
40         if($max_queue < 1)
41                 $max_queue = 500;
42
43         $batch_queue = get_config('system','max_batch_queue');
44         if($batch_queue < 1)
45                 $batch_queue = 1000;
46
47         $r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` 
48                 WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
49                 intval($cid)
50         );
51         if($r && count($r)) {
52                 if($batch &&  ($r[0]['total'] > $batch_queue)) {
53                         logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
54                         return;
55                 }
56                 elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
57                         logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
58                         return;
59                 }
60         }
61
62         q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
63                 VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
64                 intval($cid),
65                 dbesc($network),
66                 dbesc(datetime_convert()),
67                 dbesc(datetime_convert()),
68                 dbesc($msg),
69                 intval(($batch) ? 1: 0)
70         );
71
72 }