Don't overwrite already replaced cache file paths

This commit is contained in:
Michael 2022-05-08 08:53:18 +00:00
parent 2d856f48b7
commit 7b0187c4c5

View file

@ -1587,8 +1587,8 @@ class Contact
self::updateAvatar($cid, $contact['avatar'], true); self::updateAvatar($cid, $contact['avatar'], true);
return; return;
} }
} elseif (!empty($contact['photo']) || !empty($contact['thumb']) || !empty($contact['micro'])) { } elseif (!self::getAvatarFile($contact['photo']) || !self::getAvatarFile($contact['thumb']) || !self::getAvatarFile($contact['micro'])) {
Logger::info('Removing avatar cache', ['id' => $cid, 'contact' => $contact]); Logger::info('Removing/replacing avatar cache', ['id' => $cid, 'contact' => $contact]);
self::updateAvatar($cid, $contact['avatar'], true); self::updateAvatar($cid, $contact['avatar'], true);
return; return;
} }
@ -2090,10 +2090,12 @@ class Contact
self::deleteAvatarCache($contact['photo']); self::deleteAvatarCache($contact['photo']);
self::deleteAvatarCache($contact['thumb']); self::deleteAvatarCache($contact['thumb']);
self::deleteAvatarCache($contact['micro']); self::deleteAvatarCache($contact['micro']);
Logger::debug('Avatar file name changed', ['new' => $avatar, 'old' => $contact['avatar']]);
} elseif (self::getAvatarFile($contact['photo']) && self::getAvatarFile($contact['thumb']) && self::getAvatarFile($contact['micro'])) { } elseif (self::getAvatarFile($contact['photo']) && self::getAvatarFile($contact['thumb']) && self::getAvatarFile($contact['micro'])) {
$fields['photo'] = $contact['photo']; $fields['photo'] = $contact['photo'];
$fields['thumb'] = $contact['thumb']; $fields['thumb'] = $contact['thumb'];
$fields['thumb'] = $contact['thumb']; $fields['thumb'] = $contact['thumb'];
Logger::debug('Using existing cache files', ['uri-id' => $contact['uri-id'], 'fields' => $fields]);
return $fields; return $fields;
} }
@ -2105,11 +2107,13 @@ class Contact
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
$img_str = $fetchResult->getBody(); $img_str = $fetchResult->getBody();
if (empty($img_str)) { if (empty($img_str)) {
Logger::debug('Avatar is invalid', ['avatar' => $avatar]);
return $fields; return $fields;
} }
$image = new Image($img_str, Images::getMimeTypeByData($img_str)); $image = new Image($img_str, Images::getMimeTypeByData($img_str));
if (!$image->isValid()) { if (!$image->isValid()) {
Logger::debug('Avatar picture is invalid', ['avatar' => $avatar]);
return $fields; return $fields;
} }
@ -2117,7 +2121,7 @@ class Contact
$fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB); $fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB);
$fields['micro'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_MICRO); $fields['micro'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_MICRO);
Logger::debug('Storing avatar cache', ['uri-id' => $contact['uri-id'], 'fields' => $fields]); Logger::debug('Storing new avatar cache', ['uri-id' => $contact['uri-id'], 'fields' => $fields]);
return $fields; return $fields;
} }