2 require_once("boot.php");
3 require_once('include/queue_fn.php');
5 function queue_run($argv, $argc){
13 @include(".htconfig.php");
14 require_once("dba.php");
15 $db = new dba($db_host, $db_user, $db_pass, $db_data);
16 unset($db_host, $db_user, $db_pass, $db_data);
20 require_once("session.php");
21 require_once("datetime.php");
22 require_once('include/items.php');
23 require_once('include/bbcode.php');
25 load_config('config');
26 load_config('system');
28 $a->set_baseurl(get_config('system','url'));
33 $queue_id = intval($argv[1]);
39 logger('queue: start');
41 $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
43 $r = q("select * from deliverq where 1");
46 logger('queue: deliverq');
47 proc_run('php','include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']);
49 @time_sleep_until(microtime(true) + (float) $interval);
53 $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
54 LEFT JOIN `contact` ON `queue`.`cid` = `contact`.`id`
55 WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
58 logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
59 logger('Expired queue data :' . $rr['content'], LOGGER_DATA);
61 q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
65 $r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1",
69 $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ");
76 call_hooks('queue_predeliver', $a, $r);
81 require_once('include/salmon.php');
82 require_once('include/diaspora.php');
84 foreach($r as $q_item) {
86 // queue_predeliver hooks may have changed the queue db details,
87 // so check again if this entry still needs processing
90 $qi = q("select * from queue where `id` = %d limit 1",
95 $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
103 $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
104 intval($qi[0]['cid'])
107 remove_queue_item($q_item['id']);
110 if(in_array($c[0]['notify'],$deadguys)) {
111 logger('queue: skipping known dead url: ' . $c[0]['notify']);
112 update_queue_time($q_item['id']);
116 $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
117 FROM `user` WHERE `uid` = %d LIMIT 1",
121 remove_queue_item($q_item['id']);
125 $data = $qi[0]['content'];
126 $public = $qi[0]['batch'];
132 switch($contact['network']) {
134 logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
135 $deliver_status = dfrn_deliver($owner,$contact,$data);
137 if($deliver_status == (-1)) {
138 update_queue_time($q_item['id']);
139 $deadguys[] = $contact['notify'];
142 remove_queue_item($q_item['id']);
145 case NETWORK_OSTATUS:
146 if($contact['notify']) {
147 logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
148 $deliver_status = slapper($owner,$contact['notify'],$data);
150 if($deliver_status == (-1))
151 update_queue_time($q_item['id']);
153 remove_queue_item($q_item['id']);
156 case NETWORK_DIASPORA:
157 if($contact['notify']) {
158 logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
159 $deliver_status = diaspora_transmit($owner,$contact,$data,$public);
161 if($deliver_status == (-1))
162 update_queue_time($q_item['id']);
164 remove_queue_item($q_item['id']);
169 $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
170 call_hooks('queue_deliver', $a, $params);
172 if($params['result'])
173 remove_queue_item($q_item['id']);
175 update_queue_time($q_item['id']);
186 if (array_search(__file__,get_included_files())===0){
187 queue_run($argv,$argc);