aboutsummaryrefslogtreecommitdiffstats
path: root/include/deliver.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/deliver.php')
-rw-r--r--include/deliver.php110
1 files changed, 9 insertions, 101 deletions
diff --git a/include/deliver.php b/include/deliver.php
index de93e316e..60d935d02 100644
--- a/include/deliver.php
+++ b/include/deliver.php
@@ -2,6 +2,7 @@
require_once('include/cli_startup.php');
require_once('include/zot.php');
+require_once('include/queue_fn.php');
function deliver_run($argv, $argc) {
@@ -15,7 +16,6 @@ function deliver_run($argv, $argc) {
logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
-
for($x = 1; $x < $argc; $x ++) {
$dresult = null;
@@ -24,87 +24,6 @@ function deliver_run($argv, $argc) {
);
if($r) {
- /**
- * Check to see if we have any recent communications with this hub (in the last month).
- * If not, reduce the outq_priority.
- */
-
- $base = '';
-
- $h = parse_url($r[0]['outq_posturl']);
- if($h) {
- $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
- if($base !== z_root()) {
- $y = q("select site_update, site_dead from site where site_url = '%s' ",
- dbesc($base)
- );
- if($y) {
- if(intval($y[0]['site_dead'])) {
- q("delete from outq where outq_posturl = '%s'",
- dbesc($r[0]['outq_posturl'])
- );
- logger('dead site ignored ' . $base);
- continue;
- }
- if($y[0]['site_update'] < datetime_convert('UTC','UTC','now - 1 month')) {
- q("update outq set outq_priority = %d where outq_hash = '%s'",
- intval($r[0]['outq_priority'] + 10),
- dbesc($r[0]['outq_hash'])
- );
- logger('immediate delivery deferred for site ' . $base);
- continue;
- }
- }
- else {
-
- // zot sites should all have a site record, unless they've been dead for as long as
- // your site has existed. Since we don't know for sure what these sites are,
- // call them unknown
-
- q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ",
- dbesc($base),
- dbesc(datetime_convert()),
- intval(($r[0]['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN)
- );
- }
- }
- }
-
- // "post" queue driver - used for diaspora and friendica-over-diaspora communications.
-
- if($r[0]['outq_driver'] === 'post') {
-
-
- $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']);
- if($result['success'] && $result['return_code'] < 300) {
- logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
- if($base) {
- q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
- dbesc(datetime_convert()),
- dbesc($base)
- );
- }
- q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1",
- dbesc('accepted for delivery'),
- dbesc(datetime_convert()),
- dbesc($argv[$x])
- );
-
- $y = q("delete from outq where outq_hash = '%s'",
- dbesc($argv[$x])
- );
-
- }
- else {
- logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG);
- $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'",
- dbesc(datetime_convert()),
- dbesc($argv[$x])
- );
- }
- continue;
- }
-
$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
@@ -127,9 +46,9 @@ function deliver_run($argv, $argc) {
$msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m)))));
$dresult = zot_import($msg,z_root());
}
- $r = q("delete from outq where outq_hash = '%s'",
- dbesc($argv[$x])
- );
+
+ 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)) {
@@ -152,22 +71,11 @@ function deliver_run($argv, $argc) {
);
}
}
- else {
- logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
- $result = zot_zot($r[0]['outq_posturl'],$r[0]['outq_notify']);
- if($result['success']) {
- logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']);
- zot_process_response($r[0]['outq_posturl'],$result, $r[0]);
- }
- else {
- logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']);
- logger('deliver: remote zot delivery fail data: ' . print_r($result,true), LOGGER_DATA);
- $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'",
- dbesc(datetime_convert()),
- dbesc($argv[$x])
- );
- }
- }
+
+ // otherwise it's a remote delivery - call queue_deliver();
+
+ queue_deliver($r[0],true);
+
}
}
}