aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon/Deliver.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-05-19 19:42:45 -0700
committerredmatrix <git@macgirvin.com>2016-05-19 19:42:45 -0700
commit5b2474238eb0d257db14b0668ef25eab92e53fea (patch)
tree30518577199eeb91e902ed1f3b39401268eece6c /Zotlabs/Daemon/Deliver.php
parent6e7d7c50174ffe3db78c5318dde0d9b0b1f416b8 (diff)
downloadvolse-hubzilla-5b2474238eb0d257db14b0668ef25eab92e53fea.tar.gz
volse-hubzilla-5b2474238eb0d257db14b0668ef25eab92e53fea.tar.bz2
volse-hubzilla-5b2474238eb0d257db14b0668ef25eab92e53fea.zip
first phase of daemon refactoring
Diffstat (limited to 'Zotlabs/Daemon/Deliver.php')
-rw-r--r--Zotlabs/Daemon/Deliver.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/Zotlabs/Daemon/Deliver.php b/Zotlabs/Daemon/Deliver.php
new file mode 100644
index 000000000..56f0fed78
--- /dev/null
+++ b/Zotlabs/Daemon/Deliver.php
@@ -0,0 +1,82 @@
+<?php /** @file */
+
+namespace Zotlabs\Daemon;
+
+require_once('include/zot.php');
+require_once('include/queue_fn.php');
+
+
+class Deliver {
+
+ static public function function run($argc,$argv) {
+
+ if($argc < 2)
+ return;
+
+ logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
+
+ for($x = 1; $x < $argc; $x ++) {
+
+ $dresult = null;
+ $r = q("select * from outq where outq_hash = '%s' limit 1",
+ dbesc($argv[$x])
+ );
+ if($r) {
+
+ $notify = json_decode($r[0]['outq_notify'],true);
+
+ // 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.
+
+ if(($r[0]['outq_posturl'] === z_root() . '/post') && ($r[0]['outq_msg'])) {
+ logger('deliver: local delivery', LOGGER_DEBUG);
+
+ // 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) {
+ $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $mm)))));
+ zot_import($msg,z_root());
+ }
+ }
+ else {
+ $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m)))));
+ $dresult = zot_import($msg,z_root());
+ }
+
+ remove_queue_item($r[0]['outq_hash']);
+
+ 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'])
+ );
+ }
+ }
+ }
+ }
+
+ q("delete from dreport where dreport_queue = '%s'",
+ dbesc($argv[$x])
+ );
+ }
+ }
+
+ // otherwise it's a remote delivery - call queue_deliver() with the $immediate flag
+
+ queue_deliver($r[0],true);
+
+ }
+ }
+ }
+}