diff options
Diffstat (limited to 'include/connections.php')
-rw-r--r-- | include/connections.php | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/include/connections.php b/include/connections.php index 51df18b70..658fb6ee6 100644 --- a/include/connections.php +++ b/include/connections.php @@ -446,8 +446,13 @@ function contact_remove($channel_id, $abook_id) { ); $r = q("delete from abconfig where chan = %d and xchan = '%s'", - intval($channel_id), - dbesc($abook['abook_xchan']) + intval($channel_id), + dbesc($abook['abook_xchan']) + ); + + $r = q("delete from source where src_channel_id = %d and src_xchan = '%s'", + intval($channel_id), + dbesc($abook['abook_xchan']) ); return true; @@ -772,3 +777,67 @@ function vcard_query(&$r) { } } } + +function z6trans_connections() { + + $r = dbq("SELECT DISTINCT abook.abook_xchan, hubloc.hubloc_addr, hubloc.hubloc_url, hubloc.hubloc_guid, site.site_project, site.site_version FROM abook + LEFT JOIN hubloc ON abook_xchan = hubloc_hash + LEFT JOIN site ON hubloc_url = site_url + WHERE abook.abook_self = 0 AND hubloc.hubloc_network = 'zot' + AND hubloc.hubloc_deleted = 0 AND site.site_dead = 0" + ); + + foreach($r as $rr) { + if(stripos($rr['site_project'], 'hubzilla') !== false && version_compare($rr['site_version'], '4.7.4', '>=')) { + + $zot_xchan = $rr['abook_xchan']; + $guid = $rr['hubloc_guid']; + $hub_url = $rr['hubloc_url']; + $addr = $rr['hubloc_addr']; + + $x = q("SELECT hubloc_hash FROM hubloc + WHERE hubloc_guid = '%s' AND hubloc_url = '%s' AND hubloc_network = 'zot6' AND hubloc_deleted = 0", + dbesc($guid), + dbesc($hub_url) + ); + + if(!$x) { + logger("z6trans_connections: zot6 hubloc for $addr not found"); + discover_by_webbie($addr,'zot6'); + continue; + } + + $zot6_xchan = $x[0]['hubloc_hash']; + + logger("z6trans_connections: transition $zot_xchan to $zot6_xchan"); + + dbq("START TRANSACTION"); + + $q1 = q("UPDATE abook set abook_xchan = '%s' WHERE abook_xchan = '%s'", + dbesc($zot6_xchan), + dbesc($zot_xchan) + ); + + $q2 = q("UPDATE abconfig set xchan = '%s' WHERE xchan = '%s'", + dbesc($zot6_xchan), + dbesc($zot_xchan) + ); + + $q3 = q("UPDATE pgrp_member set xchan = '%s' WHERE xchan = '%s'", + dbesc($zot6_xchan), + dbesc($zot_xchan) + ); + + if($q1 && $q2 && $q3) { + dbq("COMMIT"); + logger("z6trans_connections: completed"); + continue; + } + + logger("z6trans_connections: failed - performing rollback"); + dbq("ROLLBACK"); + + } + } + +} |