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:
parent
0af2be14ee
commit
fc246424a9
|
@ -125,7 +125,7 @@ class Avatar
|
|||
|
||||
private static function getFilename(string $url): string
|
||||
{
|
||||
$guid = Item::guidFromUri($url, parse_url($url, PHP_URL_HOST));
|
||||
$guid = Item::guidFromUri($url);
|
||||
|
||||
return substr($guid, 0, 2) . '/' . substr($guid, 3, 2) . '/' . substr($guid, 5, 3) . '/' .
|
||||
substr($guid, 9, 2) .'/' . substr($guid, 11, 2) . '/' . substr($guid, 13, 4). '/' . substr($guid, 18) . '-';
|
||||
|
|
|
@ -2675,7 +2675,7 @@ class Contact
|
|||
}
|
||||
|
||||
$update = false;
|
||||
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST));
|
||||
$guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url']);
|
||||
|
||||
// make sure to not overwrite existing values with blank entries except some technical fields
|
||||
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
|
||||
|
|
|
@ -2037,6 +2037,7 @@ class Item
|
|||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,8 +59,7 @@ class Mail
|
|||
}
|
||||
|
||||
if (empty($msg['guid'])) {
|
||||
$host = parse_url($msg['from-url'], PHP_URL_HOST);
|
||||
$msg['guid'] = Item::guidFromUri($msg['uri'], $host);
|
||||
$msg['guid'] = Item::guidFromUri($msg['uri'], parse_url($msg['from-url'], PHP_URL_HOST));
|
||||
}
|
||||
|
||||
$msg['created'] = (!empty($msg['created']) ? DateTimeFormat::utc($msg['created']) : DateTimeFormat::utcNow());
|
||||
|
|
|
@ -625,8 +625,8 @@ class Feed
|
|||
|
||||
$notify = Item::isRemoteSelf($contact, $item);
|
||||
|
||||
// Distributed items should have a well formatted URI.
|
||||
// Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
|
||||
// Distributed items should have a well-formatted URI.
|
||||
// Additionally, we have to avoid conflicts with identical URI between imported feeds and these items.
|
||||
if ($notify) {
|
||||
$item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
|
||||
$item['uri'] = Item::newURI($item['guid']);
|
||||
|
|
Loading…
Reference in New Issue
Block a user