aboutsummaryrefslogtreecommitdiffstats
path: root/include/hubloc.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/hubloc.php')
-rw-r--r--include/hubloc.php73
1 files changed, 72 insertions, 1 deletions
diff --git a/include/hubloc.php b/include/hubloc.php
index 566875ce9..cdc9de4af 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -42,4 +42,75 @@ function prune_hub_reinstalls() {
}
}
}
-} \ No newline at end of file
+}
+
+function remove_obsolete_hublocs() {
+
+ logger('remove_obsolete_hublocs',LOGGER_DEBUG);
+
+ // Get rid of any hublocs which are ours but aren't valid anymore -
+ // e.g. they point to a different and perhaps transient URL that we aren't using.
+
+ // I need to stress that this shouldn't happen. fix_system_urls() fixes hublocs
+ // when it discovers the URL has changed. So it's unclear how we could end up
+ // with URLs pointing to the old site name. But it happens. This may be an artifact
+ // of an old bug or maybe a regression in some newer code. In any event, they
+ // mess up communications and we have to take action if we find any.
+
+ // First make sure we have any hublocs (at all) with this URL and sitekey.
+ // We don't want to perform this operation while somebody is in the process
+ // of renaming their hub or installing certs.
+
+ $r = q("select hubloc_id from hubloc where hubloc_url = '%s' and hubloc_sitekey = '%s'",
+ dbesc(z_root()),
+ dbesc(get_config('system','pubkey'))
+ );
+ if((! $r) || (! count($r)))
+ return;
+
+ $channels = array();
+
+ // Good. We have at least one *valid* hubloc.
+
+ // Do we have any invalid ones?
+
+ $r = q("select hubloc_id from hubloc where hubloc_sitekey = '%s' and hubloc_url != '%s'",
+ dbesc(get_config('system','pubkey')),
+ dbesc(z_root())
+ );
+ $p = q("select hubloc_id from hubloc where hubloc_sitekey != '%s' and hubloc_url = '%s'",
+ dbesc(get_config('system','pubkey')),
+ dbesc(z_root())
+ );
+ if(is_array($r) && is_array($p))
+ $r = array_merge($r,$p);
+
+ if(! $r)
+ return;
+
+ // We've got invalid hublocs. Get rid of them.
+
+ logger('remove_obsolete_hublocs: removing ' . count($r) . ' hublocs.');
+
+ $interval = ((get_config('system','delivery_interval') !== false)
+ ? intval(get_config('system','delivery_interval')) : 2 );
+
+ foreach($r as $rr) {
+ q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d limit 1",
+ intval(HUBLOC_FLAGS_DELETED),
+ intval($rr['hubloc_id'])
+ );
+
+ $x = q("select channel_id from channel where channel_hash = '%s' limit 1",
+ dbesc($rr['hubloc_hash'])
+ );
+ if($x) {
+// proc_run('php','include/notifier.php','location',$x[0]['channel_id']);
+// if($interval)
+// @time_sleep_until(microtime(true) + (float) $interval);
+ }
+ }
+}
+
+
+ \ No newline at end of file