From 1f81a2cb1b0974bf8fe6d0daf2c06a23f27afc98 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 27 Apr 2023 22:54:45 +0200 Subject: remove updates entry if a xchan_hash mismatch is encountered --- Zotlabs/Lib/Libzotdir.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'Zotlabs/Lib/Libzotdir.php') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index 5677d2263..d9b5d7a35 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -357,6 +357,11 @@ class Libzotdir { if($zf && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) { $xc = Libzot::import_xchan($zf['data']); + // xchan_hash mismatch - this can happen after a site re-install at the same url + if ($xc['success'] && $xc['hash'] !== $ud['ud_hash']) { + self::delete_by_hash($ud['ud_hash']); + } + // This is a workaround for a missing xchan_updated column // TODO: implement xchan_updated in the xchan table and update this column instead if($zf['data']['primary_location']['address'] && $zf['data']['primary_location']['url']) { @@ -365,6 +370,7 @@ class Libzotdir { dbesc($zf['data']['primary_location']['url']) ); } + return true; } } @@ -714,4 +720,28 @@ class Libzotdir { } + + /** + * @brief deletes a entry in updates by hash + * + * @param string $hash the channel hash + * @return boolean + */ + + static function delete_by_hash($hash) { + if (!$hash) { + return false; + } + + $x = q("DELETE FROM updates WHERE ud_hash = '%s'", + dbesc($hash) + ); + + if ($x) { + return true; + } + + return false; + } + } -- cgit v1.2.3