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",
71 // For the first 12 hours we'll try to deliver every 15 minutes
72 // After that, we'll only attempt delivery once per hour.
74 $r = q("SELECT `id` FROM `queue` WHERE (( `created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( `last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR ))");
81 call_hooks('queue_predeliver', $a, $r);
86 require_once('include/salmon.php');
87 require_once('include/diaspora.php');
89 foreach($r as $q_item) {
91 // queue_predeliver hooks may have changed the queue db details,
92 // so check again if this entry still needs processing
95 $qi = q("select * from queue where `id` = %d limit 1",
100 $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ",
101 intval($q_item['id'])
108 $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
109 intval($qi[0]['cid'])
112 remove_queue_item($q_item['id']);
115 if(in_array($c[0]['notify'],$deadguys)) {
116 logger('queue: skipping known dead url: ' . $c[0]['notify']);
117 update_queue_time($q_item['id']);
121 $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
122 FROM `user` WHERE `uid` = %d LIMIT 1",
126 remove_queue_item($q_item['id']);
130 $data = $qi[0]['content'];
131 $public = $qi[0]['batch'];
137 switch($contact['network']) {
139 logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
140 $deliver_status = dfrn_deliver($owner,$contact,$data);
142 if($deliver_status == (-1)) {
143 update_queue_time($q_item['id']);
144 $deadguys[] = $contact['notify'];
147 remove_queue_item($q_item['id']);
150 case NETWORK_OSTATUS:
151 if($contact['notify']) {
152 logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
153 $deliver_status = slapper($owner,$contact['notify'],$data);
155 if($deliver_status == (-1))
156 update_queue_time($q_item['id']);
158 remove_queue_item($q_item['id']);
161 case NETWORK_DIASPORA:
162 if($contact['notify']) {
163 logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
164 $deliver_status = diaspora_transmit($owner,$contact,$data,$public);
166 if($deliver_status == (-1))
167 update_queue_time($q_item['id']);
169 remove_queue_item($q_item['id']);
174 $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
175 call_hooks('queue_deliver', $a, $params);
177 if($params['result'])
178 remove_queue_item($q_item['id']);
180 update_queue_time($q_item['id']);
191 if (array_search(__file__,get_included_files())===0){
192 queue_run($argv,$argc);