aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-07-25 22:57:06 -0700
committerfriendica <info@friendica.com>2013-07-25 22:57:06 -0700
commit7f87da68baa38705b4d5080d3789be8af44b0795 (patch)
treee191ba63b4c7eeec489857c6251ec624ca3bfeda /include
parentc59fff945f6d7884622ce0ea919bc7843bafb1f0 (diff)
downloadvolse-hubzilla-7f87da68baa38705b4d5080d3789be8af44b0795.tar.gz
volse-hubzilla-7f87da68baa38705b4d5080d3789be8af44b0795.tar.bz2
volse-hubzilla-7f87da68baa38705b4d5080d3789be8af44b0795.zip
the rest of the heavy lifting on clone sync - now we're down to some log messages and a whole lot of testing
Diffstat (limited to 'include')
-rw-r--r--include/zot.php83
1 files changed, 82 insertions, 1 deletions
diff --git a/include/zot.php b/include/zot.php
index 0d509b3b4..7369de80a 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -875,7 +875,7 @@ function zot_import($arr) {
logger('Channel sync received: ' . print_r($arr,true), LOGGER_DATA);
logger('Channel sync recipients: ' . print_r($deliveries,true), LOGGER_DATA);
-// $result = process_channelsync_delivery($i['notify']['sender'],$arr,$deliveries);
+ $result = process_channel_sync_delivery($i['notify']['sender'],$arr,$deliveries);
}
}
if($result)
@@ -1602,3 +1602,84 @@ function build_sync_packet($uid = 0, $packet = null) {
}
+
+function process_channel_sync_delivery($sender,$arr,$deliveries) {
+
+// FIXME - this will sync red structures. Eventually we need to make this application agnostic.
+
+ $result = array();
+
+ foreach($deliveries as $d) {
+ $r = q("select * from channel where channel_hash = '%s' limit 1",
+ dbesc($d['hash'])
+ );
+
+ if(! $r) {
+ $result[] = array($d['hash'],'not found');
+ continue;
+ }
+
+ $channel = $r[0];
+
+ if($channel['channel_hash'] != $sender['hash']) {
+ logger('process_channel_sync_delivery: possible forgery. Sender ' . $sender['hash'] . ' is not ' . $channel['channel_hash']);
+ $result[] = array($d['hash'],'channel mismatch',$channel['channel_name']);
+ continue;
+ }
+
+ if(array_key_exists('config',$arr) && is_array($arr['config']) && count($arr['config'])) {
+ foreach($arr['config'] as $cat => $k) {
+ foreach($arr['config'][$cat] as $k => $v)
+ set_pconfig($channel['channel_id'],$cat,$k,$v);
+ }
+ }
+
+ if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
+ $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey');
+
+ $clean = array();
+ foreach($arr['channel'] as $k => $v) {
+ if(in_array($k,$disallowed))
+ continue;
+ $clean[$k] = $v;
+ }
+ if(count($clean)) {
+ foreach($clean as $k => $v) {
+ $r = dbq("UPDATE channel set " . dbesc($k) . " = '" . dbesc($v)
+ . "' where channel_id = " . intval($channel['channel_id']) . " limit 1");
+ }
+ }
+ }
+
+
+ if(array_key_exists('abook',$arr) && is_array($arr['abook']) && count($arr['abook'])) {
+
+ $disallowed = array('abook_id','abook_account','abook_channel');
+
+ $clean = array();
+ foreach($arr['abook'] as $abook) {
+ foreach($abook as $k => $v) {
+ if(in_array($k,$disallowed))
+ continue;
+ $clean[$k] = $v;
+ }
+
+ if(! array_key_exists('abook_xchan',$clean))
+ continue;
+
+ if(count($clean)) {
+ foreach($clean as $k => $v) {
+ $r = dbq("UPDATE abook set " . dbesc($k) . " = '" . dbesc($v)
+ . "' where abook_xchan = '" . dbesc($clean['abook_xchan']) . "' and abook_channel = " . intval($channel['channel_id'])
+ . " limit 1");
+ }
+ }
+ }
+ }
+
+ $result[] = array($d['hash'],'channel sync updated',$channel['channel_name']);
+
+
+ }
+ return $result;
+}