diff options
author | Mario Vavti <mario@mariovavti.com> | 2023-04-12 09:29:51 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2023-04-12 09:29:51 +0200 |
commit | 7ce4175876ce13727432dc839938bb8e486ef406 (patch) | |
tree | 5128e5c5d13629628c0e50b4a91935cfeda44a20 /Zotlabs/Lib | |
parent | 03bdbfa705ba490b0450f063753100557f5d8bae (diff) | |
download | volse-hubzilla-7ce4175876ce13727432dc839938bb8e486ef406.tar.gz volse-hubzilla-7ce4175876ce13727432dc839938bb8e486ef406.tar.bz2 volse-hubzilla-7ce4175876ce13727432dc839938bb8e486ef406.zip |
initial commit directory sync rewrite - should work but still requires lots of cleanup
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r-- | Zotlabs/Lib/Libsync.php | 2 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 16 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzotdir.php | 67 |
3 files changed, 65 insertions, 20 deletions
diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index d52b501e4..56bb411c4 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -786,7 +786,7 @@ class Libsync { if (isset($arr['locations']) && $arr['locations']) { - $xisting = q("select * from hubloc where hubloc_hash = '%s'", + $xisting = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", dbesc($sender['hash']) ); diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index a8334595f..b41ba043a 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -920,11 +920,11 @@ class Libzot { $s = Libsync::sync_locations($arr, $arr); if ($s) { - if (isset($s['change_message'])) + if (!empty($s['change_message'])) $what .= $s['change_message']; - if (isset($s['changed'])) + if (!empty($s['changed'])) $changed = $s['changed']; - if (isset($s['message'])) + if (!empty($s['message'])) $ret['message'] .= $s['message']; } @@ -977,17 +977,15 @@ class Libzot { } } - if (($changed) || ($ud_flags == UPDATE_FLAGS_FORCED)) { + if ($changed/* || ($ud_flags == UPDATE_FLAGS_FORCED)*/) { $guid = random_string() . '@' . \App::get_hostname(); Libzotdir::update_modtime($xchan_hash, $guid, $address, $ud_flags); - logger('Changed: ' . $what, LOGGER_DEBUG); } elseif (!$ud_flags) { // nothing changed but we still need to update the updates record - q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ", - intval(UPDATE_FLAGS_UPDATED), - dbesc($address), - intval(UPDATE_FLAGS_UPDATED) + q("update updates set ud_flags = 0, ud_date = '%s' where ud_hash = '%s'", + dbesc(datetime_convert()), + dbesc($xchan_hash) ); } diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index dfedd0bc8..ed2095059 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -265,16 +265,36 @@ class Libzotdir { if (is_array($j['transactions']) && count($j['transactions'])) { foreach ($j['transactions'] as $t) { - if (empty($t['hash']) || empty($t['transaction_id']) || empty($t['address'])) { + if (empty($t['hash'])) { continue; } - $r = q("select * from updates where ud_guid = '%s' limit 1", - dbesc($t['transaction_id']) + $r = q("select * from updates where ud_hash = '%s' limit 1", + dbesc($t['hash']) ); - if($r) - continue; + if ($r) { + + if ($r[0]['ud_date'] >= $t['timestamp']) { + continue; + } + + q("UPDATE updates SET ud_flags = 1 WHERE ud_id = %d", + dbesc($r[0]['ud_id']) + ); + } + else { + $t['transaction_id'] = strpos($t['transaction_id'], '@') === false ? $t['transaction_id'] : substr($t['transaction_id'], strpos($t['transaction_id'], '@') + 1); + q("insert into updates ( ud_hash, ud_guid, ud_date, ud_addr, ud_flags ) + values ( '%s', '%s', '%s', '%s', 1 ) ", + dbesc($t['hash']), + dbesc($t['transaction_id']), + dbesc($t['timestamp']), + dbesc($t['address']) + ); + } + +/* $ud_flags = 0; if (is_array($t['flags']) && in_array('deleted',$t['flags'])) $ud_flags |= UPDATE_FLAGS_DELETED; @@ -289,6 +309,7 @@ class Libzotdir { intval($ud_flags), dbesc($t['address']) ); +*/ } } } @@ -313,7 +334,7 @@ class Libzotdir { logger('update_directory_entry: ' . print_r($ud,true), LOGGER_DATA); - if ($ud['ud_addr'] && (! ($ud['ud_flags'] & UPDATE_FLAGS_DELETED))) { + if ($ud['ud_hash'] /* && (! ($ud['ud_flags'] & UPDATE_FLAGS_DELETED))*/) { $success = false; $zf = []; @@ -331,10 +352,11 @@ class Libzotdir { dbesc($zf['data']['primary_location']['url']) ); } - - q("update updates set ud_last = '%s' where ud_addr = '%s'", + } + else { + q("UPDATE updates SET ud_last = '%s' WHERE ud_hash = '%s'", dbesc(datetime_convert()), - dbesc($ud['ud_addr']) + dbesc($ud['ud_hash']) ); } } @@ -430,7 +452,7 @@ class Libzotdir { } $ud_hash = random_string() . '@' . \App::get_hostname(); - self::update_modtime($hash, $ud_hash, channel_reddress($p[0]),(($force) ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED)); + self::update_modtime($hash, $ud_hash, channel_reddress($p[0]), 0); } @@ -657,6 +679,30 @@ class Libzotdir { return; } + $u = q("SELECT ud_id FROM updates WHERE ud_hash = '%s' LIMIT 1", + dbesc($hash) + ); + + if ($u) { + $x = q("UPDATE updates SET ud_date = '%s', ud_guid = '%s', ud_addr = '%s', ud_flags = 0 WHERE ud_id = %d", + dbesc(datetime_convert()), + dbesc(\App::get_hostname()), + dbesc($addr), + intval($u[0]['ud_id']) + ); + + return; + } + + q("INSERT INTO updates (ud_hash, ud_guid, ud_date, ud_addr ) VALUES ( '%s', '%s', '%s', '%s' )", + dbesc($hash), + dbesc(\App::get_hostname()), + dbesc(datetime_convert()), + dbesc($addr) + ); + + return; +/* if($flags) { q("insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' )", dbesc($hash), @@ -673,6 +719,7 @@ class Libzotdir { intval(UPDATE_FLAGS_UPDATED) ); } +*/ } } |