Provide default host value to hash() in Model\Item::guidFromUri

- Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1338133783
This commit is contained in:
Hypolite Petovan 2022-12-07 22:21:23 -05:00
parent 0af2be14ee
commit fc246424a9
5 changed files with 14 additions and 9 deletions

View file

@ -2034,9 +2034,10 @@ class Item
* Posts that are created on this system are using System::createUUID.
* Received ActivityPub posts are using Processor::getGUIDByURL.
*
* @param string $uri uri of an item entry
* @param string $uri uri of an item entry
* @param string|null $host hostname for the GUID prefix
* @return string Unique guid
* @throws \Exception
*/
public static function guidFromUri(string $uri, string $host = null): string
{
@ -2047,11 +2048,16 @@ class Item
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
unset($parsed['scheme']);
$hostPart = $host ?? $parsed['host'] ?? '';
if (!$hostPart) {
Logger::warning('Empty host GUID part', ['uri' => $uri, 'host' => $host, 'parsed' => $parsed, 'callstack' => System::callstack(10)]);
}
// Glue it together to be able to make a hash from it
$host_id = implode('/', $parsed);
// Use a mixture of several hashes to provide some GUID like experience
return hash('crc32', $host) . '-'. hash('joaat', $host_id) . '-'. hash('fnv164', $host_id);
return hash('crc32', $hostPart) . '-' . hash('joaat', $host_id) . '-' . hash('fnv164', $host_id);
}
/**