remove updates entry if a xchan_hash mismatch is encountered

This commit is contained in:
Mario Vavti
2023-04-27 22:54:45 +02:00
parent 5da58d42f6
commit 1f81a2cb1b

View File

@@ -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;
}
}