2013-02-26 01:09:40 +00:00
|
|
|
<?php /** @file */
|
2012-11-20 00:51:15 +00:00
|
|
|
|
|
|
|
require_once('include/cli_startup.php');
|
|
|
|
require_once('include/zot.php');
|
|
|
|
|
|
|
|
|
|
|
|
function deliver_run($argv, $argc) {
|
|
|
|
|
|
|
|
cli_startup();
|
|
|
|
|
|
|
|
$a = get_app();
|
|
|
|
|
|
|
|
if($argc < 2)
|
|
|
|
return;
|
|
|
|
|
2014-07-02 05:02:36 +00:00
|
|
|
logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
|
2012-11-20 00:51:15 +00:00
|
|
|
|
|
|
|
for($x = 1; $x < $argc; $x ++) {
|
|
|
|
$r = q("select * from outq where outq_hash = '%s' limit 1",
|
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
|
|
|
if($r) {
|
2014-08-26 23:35:06 +00:00
|
|
|
if($r[0]['outq_driver'] === 'post') {
|
|
|
|
$result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']);
|
2014-08-27 01:58:48 +00:00
|
|
|
if($result['success'] && $result['return_code'] < 300) {
|
2014-08-26 23:35:06 +00:00
|
|
|
logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
|
2014-08-29 05:55:40 +00:00
|
|
|
$y = q("delete from outq where outq_hash = '%s' limit 1",
|
2014-08-29 04:49:13 +00:00
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
2014-08-26 23:35:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-08-30 00:31:40 +00:00
|
|
|
logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG);
|
2014-08-26 23:35:06 +00:00
|
|
|
$y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1",
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-31 02:15:03 +00:00
|
|
|
$notify = json_decode($r[0]['outq_notify'],true);
|
|
|
|
|
|
|
|
$sendtoweb = false;
|
|
|
|
if(array_key_exists('iv',$notify) && (! $r[0]['outq_msg']))
|
|
|
|
$sendtoweb = true;
|
|
|
|
|
|
|
|
if(($r[0]['outq_posturl'] === z_root() . '/post') && (! $sendtoweb)) {
|
2014-07-02 05:02:36 +00:00
|
|
|
logger('deliver: local delivery', LOGGER_DEBUG);
|
2012-12-03 04:54:20 +00:00
|
|
|
// local delivery
|
|
|
|
// we should probably batch these and save a few delivery processes
|
2013-06-14 23:54:58 +00:00
|
|
|
// If there is no outq_msg, this is a refresh_all message which does not require local handling
|
2014-10-31 02:15:03 +00:00
|
|
|
// also send 'request' packets to the webservice so it can decode the packet
|
2013-06-14 23:54:58 +00:00
|
|
|
if($r[0]['outq_msg']) {
|
2014-10-31 02:15:03 +00:00
|
|
|
$m = json_decode($r[0]['outq_msg'],true);
|
|
|
|
if(array_key_exists('message_list',$m)) {
|
|
|
|
foreach($m['message_list'] as $mm) {
|
|
|
|
$msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $mm)))));
|
|
|
|
zot_import($msg,z_root());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$msg = array('body' => json_encode(array('pickup' => array(array('notify' => $notify,'message' => $m)))));
|
|
|
|
zot_import($msg,z_root());
|
|
|
|
}
|
2013-06-14 23:54:58 +00:00
|
|
|
$r = q("delete from outq where outq_hash = '%s' limit 1",
|
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
|
|
|
}
|
2012-11-20 00:51:15 +00:00
|
|
|
}
|
2012-12-03 04:54:20 +00:00
|
|
|
else {
|
2014-07-02 05:02:36 +00:00
|
|
|
logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
|
2012-12-03 04:54:20 +00:00
|
|
|
$result = zot_zot($r[0]['outq_posturl'],$r[0]['outq_notify']);
|
|
|
|
if($result['success']) {
|
2012-12-31 22:45:26 +00:00
|
|
|
zot_process_response($r[0]['outq_posturl'],$result, $r[0]);
|
2012-12-03 04:54:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1",
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
dbesc($argv[$x])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-11-20 00:51:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_search(__file__,get_included_files())===0){
|
|
|
|
deliver_run($argv,$argc);
|
|
|
|
killme();
|
|
|
|
}
|