2015-08-23 22:38:18 +02:00
|
|
|
<?php /** @file */
|
|
|
|
|
|
|
|
require_once('include/cli_startup.php');
|
|
|
|
require_once('include/zot.php');
|
2016-01-12 02:47:38 +01:00
|
|
|
require_once('include/queue_fn.php');
|
2015-08-23 22:38:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
function deliver_run($argv, $argc) {
|
|
|
|
|
|
|
|
cli_startup();
|
|
|
|
|
|
|
|
$a = get_app();
|
|
|
|
|
|
|
|
if($argc < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
|
|
|
|
|
|
|
|
for($x = 1; $x < $argc; $x ++) {
|
2015-10-24 13:04:14 +02:00
|
|
|
|
|
|
|
$dresult = null;
|
2015-08-23 22:38:18 +02:00
|
|
|
$r = q("select * from outq where outq_hash = '%s' limit 1",
|
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
|
|
|
if($r) {
|
|
|
|
|
|
|
|
$notify = json_decode($r[0]['outq_notify'],true);
|
|
|
|
|
2015-12-06 02:08:25 +01:00
|
|
|
// Messages without an outq_msg will need to go via the web, even if it's a
|
|
|
|
// local delivery. This includes conversation requests and refresh packets.
|
2015-08-23 22:38:18 +02:00
|
|
|
|
2015-12-06 02:08:25 +01:00
|
|
|
if(($r[0]['outq_posturl'] === z_root() . '/post') && ($r[0]['outq_msg'])) {
|
2015-08-23 22:38:18 +02:00
|
|
|
logger('deliver: local delivery', LOGGER_DEBUG);
|
2016-01-12 02:47:38 +01:00
|
|
|
|
2015-08-23 22:38:18 +02:00
|
|
|
// local delivery
|
|
|
|
// we should probably batch these and save a few delivery processes
|
|
|
|
|
|
|
|
if($r[0]['outq_msg']) {
|
|
|
|
$m = json_decode($r[0]['outq_msg'],true);
|
|
|
|
if(array_key_exists('message_list',$m)) {
|
|
|
|
foreach($m['message_list'] as $mm) {
|
2015-10-24 13:04:14 +02:00
|
|
|
$msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $mm)))));
|
2015-08-23 22:38:18 +02:00
|
|
|
zot_import($msg,z_root());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-10-24 13:04:14 +02:00
|
|
|
$msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m)))));
|
|
|
|
$dresult = zot_import($msg,z_root());
|
2015-08-23 22:38:18 +02:00
|
|
|
}
|
2016-01-12 02:47:38 +01:00
|
|
|
|
|
|
|
remove_queue_item($r[0]['outq_hash']);
|
|
|
|
|
2015-10-24 13:04:14 +02:00
|
|
|
if($dresult && is_array($dresult)) {
|
|
|
|
foreach($dresult as $xx) {
|
|
|
|
if(is_array($xx) && array_key_exists('message_id',$xx)) {
|
|
|
|
if(delivery_report_is_storable($xx)) {
|
|
|
|
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ",
|
|
|
|
dbesc($xx['message_id']),
|
|
|
|
dbesc($xx['location']),
|
|
|
|
dbesc($xx['recipient']),
|
|
|
|
dbesc($xx['status']),
|
|
|
|
dbesc(datetime_convert($xx['date'])),
|
|
|
|
dbesc($xx['sender'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-12 02:47:38 +01:00
|
|
|
q("delete from dreport where dreport_queue = '%s'",
|
2015-08-23 22:38:18 +02:00
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 02:47:38 +01:00
|
|
|
|
|
|
|
// otherwise it's a remote delivery - call queue_deliver() with the $immediate flag
|
|
|
|
|
|
|
|
queue_deliver($r[0],true);
|
|
|
|
|
2015-08-23 22:38:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_search(__file__,get_included_files())===0){
|
|
|
|
deliver_run($argv,$argc);
|
|
|
|
killme();
|
|
|
|
}
|