aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Fhubloc_id_url.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-11-05 08:46:42 +0000
committerMario <mario@mariovavti.com>2020-11-05 08:46:42 +0000
commitbafbf0416462c6f18c3fb6c8c06a063c8d6fdae6 (patch)
tree8929845be585b09d0f420621281c5531e1efad3e /Zotlabs/Module/Fhubloc_id_url.php
parent6f93d9848c43019d43ea76c27d42d657ba031cd7 (diff)
parentfdefa101d84dc2a9424eaedbdb003a4c30ec5d01 (diff)
downloadvolse-hubzilla-bafbf0416462c6f18c3fb6c8c06a063c8d6fdae6.tar.gz
volse-hubzilla-bafbf0416462c6f18c3fb6c8c06a063c8d6fdae6.tar.bz2
volse-hubzilla-bafbf0416462c6f18c3fb6c8c06a063c8d6fdae6.zip
Merge branch '5.0RC'5.0
Diffstat (limited to 'Zotlabs/Module/Fhubloc_id_url.php')
-rw-r--r--Zotlabs/Module/Fhubloc_id_url.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/Zotlabs/Module/Fhubloc_id_url.php b/Zotlabs/Module/Fhubloc_id_url.php
new file mode 100644
index 000000000..a5627a33d
--- /dev/null
+++ b/Zotlabs/Module/Fhubloc_id_url.php
@@ -0,0 +1,79 @@
+<?php
+namespace Zotlabs\Module;
+
+/* fix missing or hubloc_id_url entries */
+
+class Fhubloc_id_url extends \Zotlabs\Web\Controller {
+
+ function get() {
+
+ if(! is_site_admin())
+ return;
+
+ q("START TRANSACTION");
+
+ // remove broken xchan entries
+ $r0 = dbq("DELETE FROM xchan WHERE xchan_hash = ''");
+
+ // remove broken hubloc entries
+ $r1 = dbq("DELETE FROM hubloc WHERE hubloc_hash = ''");
+
+ // fix legacy zot hubloc_id_url
+ $r2 = dbq("UPDATE hubloc
+ SET hubloc_id_url = CONCAT(hubloc_url, '/channel/', SUBSTRING(hubloc_addr FROM 1 FOR POSITION('@' IN hubloc_addr) -1))
+ WHERE hubloc_network = 'zot'
+ AND hubloc_id_url = ''"
+ );
+
+ // fix singleton networks hubloc_id_url
+ if(ACTIVE_DBTYPE == DBTYPE_MYSQL) {
+ // fix entries for activitypub which miss the xchan_url due to an earlier bug
+ $r3 = dbq("UPDATE xchan
+ SET xchan_url = xchan_hash
+ WHERE xchan_network = 'activitypub'
+ AND xchan_url = ''"
+ );
+
+ $r4 = dbq("UPDATE hubloc
+ LEFT JOIN xchan ON hubloc.hubloc_hash = xchan.xchan_hash
+ SET hubloc.hubloc_id_url = xchan.xchan_url
+ WHERE hubloc.hubloc_network IN ('activitypub', 'diaspora', 'friendica-over-diaspora', 'gnusoc')
+ AND hubloc.hubloc_id_url = ''
+ AND xchan.xchan_url IS NOT NULL"
+ );
+
+ }
+ if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
+ // fix entries for activitypub which miss the xchan_url due to an earlier bug
+ $r3 = dbq("UPDATE xchan
+ SET xchan_url = xchan_hash
+ WHERE xchan_network = 'activitypub'
+ AND xchan_url = ''"
+ );
+
+ $r4 = dbq("UPDATE hubloc
+ SET hubloc_id_url = xchan_url
+ FROM xchan
+ WHERE hubloc_hash = xchan_hash
+ AND hubloc_network IN ('activitypub', 'diaspora', 'friendica-over-diaspora', 'gnusoc')
+ AND hubloc_id_url = ''
+ AND xchan_url IS NOT NULL"
+ );
+
+
+ }
+
+ if($r0 && $r1 && $r2 && $r3 && $r4) {
+ // remove hubloc entries where hubloc_id_url could not be fixed
+ $r5 = dbq("DELETE FROM hubloc WHERE hubloc_id_url = ''");
+ }
+
+ if($r0 && $r1 && $r2 && $r3 && $r4 && $r5) {
+ q("COMMIT");
+ return 'Completed';
+ }
+
+ q("ROLLBACK");
+ return 'Failed';
+ }
+}