diff options
author | Mario Vavti <mario@mariovavti.com> | 2023-04-28 08:57:21 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2023-04-28 08:57:21 +0200 |
commit | 3543e6dd32bd7e518a0deec2038eafe6a183dc6b (patch) | |
tree | 6ae14b855bb7714f9f5bd27e8181bdd10360b809 | |
parent | 5412ba617dfbba9161484094427075480ae4b80c (diff) | |
download | volse-hubzilla-3543e6dd32bd7e518a0deec2038eafe6a183dc6b.tar.gz volse-hubzilla-3543e6dd32bd7e518a0deec2038eafe6a183dc6b.tar.bz2 volse-hubzilla-3543e6dd32bd7e518a0deec2038eafe6a183dc6b.zip |
slightly refactor dir sync
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 5 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzotdir.php | 51 | ||||
-rw-r--r-- | Zotlabs/Module/Dircensor.php | 2 | ||||
-rw-r--r-- | boot.php | 5 |
4 files changed, 25 insertions, 38 deletions
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index d34afb83d..093670338 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -674,7 +674,6 @@ class Libzot { $arr['hash'] = $xchan_hash; $import_photos = false; - $xchan_censored = 0; $sig_methods = ((array_key_exists('signing', $arr) && is_array($arr['signing'])) ? $arr['signing'] : ['sha256']); $verified = false; @@ -706,8 +705,6 @@ class Libzot { if ($arr['photo'] && array_key_exists('updated', $arr['photo']) && $arr['photo']['updated'] > $r[0]['xchan_photo_date']) $import_photos = true; - $xchan_censored = $r[0]['xchan_censored'] ?? 0; - // if we import an entry from a site that's not ours and either or both of us is off the grid - hide the entry. /** @TODO: check if we're the same directory realm, which would mean we are allowed to see it */ @@ -969,7 +966,7 @@ class Libzot { } // update updates if anything changed bump the ud_date - Libzotdir::update($xchan_hash, $address, $xchan_censored, $changed); + Libzotdir::update($xchan_hash, $address, $changed); if (empty($ret['message'])) { $ret['success'] = true; diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index 908f60765..c3ff026d7 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -283,27 +283,29 @@ class Libzotdir { // there is more recent xchan information if ($r[0]['ud_date'] <= $t['timestamp']) { - $update = DIRECTORY_UPDATE_XCHAN; + $update = 1; } - // the host is trusted and flags have changed + // the host is trusted and flags have changed - update flags immediately if (in_array($t['host'], $dir_trusted_hosts) && $rr['site_url'] === $t['host'] && intval($r[0]['ud_flags']) !== intval($t['flags'])) { - $update = (($update) ? DIRECTORY_UPDATE_BOTH : DIRECTORY_UPDATE_FLAGS); - } - - if (!$update) { - continue; - } - - if (in_array($update, [DIRECTORY_UPDATE_FLAGS, DIRECTORY_UPDATE_BOTH])) { q("UPDATE updates SET ud_update = %d, ud_flags = %d WHERE ud_id = %d", intval($update), intval($t['flags']), dbesc($r[0]['ud_id']) ); + + q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'", + intval($t['flags']), + dbesc($r[0]['ud_hash']) + ); + + continue; + } + + if (!$update) { continue; } @@ -347,20 +349,8 @@ class Libzotdir { logger('update_directory_entry: ' . print_r($ud,true), LOGGER_DATA); - // set the flag if requested? - if (in_array($ud['ud_update'], [DIRECTORY_UPDATE_FLAGS, DIRECTORY_UPDATE_BOTH])) { - - q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'", - intval($ud['ud_flags']), - dbesc($ud['ud_hash']) - ); - } - - if (intval($ud['ud_update']) === DIRECTORY_UPDATE_FLAGS) { - self::update($ud['ud_hash'], $ud['ud_addr'], $ud['ud_flags'], false); - return true; - } - + // TODO: remove this check after all directory servers have version > 8.4 + // ud_addr will always be the channel url at that time $href = ((strpos($ud['ud_addr'], '://') === false) ? Webfinger::zot_url(punify($ud['ud_addr'])) : punify($ud['ud_addr'])); if($href) { $zf = Zotfinger::exec($href); @@ -477,7 +467,7 @@ class Libzotdir { ); } - self::update($hash, $p[0]['xchan_url'], $p[0]['xchan_censored']); + self::update($hash, $p[0]['xchan_url']); } @@ -685,7 +675,7 @@ class Libzotdir { * @param bool $bump_date (optional) default true */ - static function update($hash, $addr, $flag, $bump_date = true) { + static function update($hash, $addr, $bump_date = true, $flag = null) { $dirmode = intval(get_config('system', 'directory_mode')); @@ -706,12 +696,17 @@ class Libzotdir { $date_sql = "ud_date = '" . dbesc(datetime_convert()) . "',"; } + $flag_sql = ''; + if ($flag !== null) { + $flag_sql = "ud_flag = '" . intval($flag) . "',"; + } + + if ($u) { - $x = q("UPDATE updates SET $date_sql ud_last = '%s', ud_host = '%s', ud_addr = '%s', ud_update = 0, ud_flags = %d WHERE ud_id = %d", + $x = q("UPDATE updates SET $date_sql $flag_sql ud_last = '%s', ud_host = '%s', ud_addr = '%s', ud_update = 0 WHERE ud_id = %d", dbesc(NULL_DATE), dbesc(z_root()), dbesc($addr), - intval($flag), intval($u[0]['ud_id']) ); diff --git a/Zotlabs/Module/Dircensor.php b/Zotlabs/Module/Dircensor.php index b372bbf25..44c9148e8 100644 --- a/Zotlabs/Module/Dircensor.php +++ b/Zotlabs/Module/Dircensor.php @@ -45,7 +45,7 @@ class Dircensor extends Controller { $flag = DIRECTORY_FLAG_HIDDEN; } - Libzotdir::update($xchan, $r[0]['xchan_url'], $flag); + Libzotdir::update($xchan, $r[0]['xchan_url'], true, $flag); q("update xchan set xchan_censored = %d where xchan_hash = '%s'", intval($flag), @@ -84,11 +84,6 @@ define('DIRECTORY_MODE_PRIMARY', 0x0001); // There can only be *one* primary dir define('DIRECTORY_MODE_SECONDARY', 0x0002); // All other mirror directory servers define('DIRECTORY_MODE_STANDALONE', 0x0100); // A detached (off the grid) hub with itself as directory server. -define('DIRECTORY_UPDATE_OK', 0); -define('DIRECTORY_UPDATE_XCHAN', 1); -define('DIRECTORY_UPDATE_FLAGS', 2); -define('DIRECTORY_UPDATE_BOTH', 3); - define('DIRECTORY_FLAG_OK', 0); define('DIRECTORY_FLAG_UNSAFE', 1); define('DIRECTORY_FLAG_HIDDEN', 2); |