X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=cacc3e4f1ef1a7b56bbfc0697893b0c745a8e79e;hb=d2c734c0256a2b6e8a5eef4422480edd820544b1;hp=ae715840eb038e7ac0f4b0f41da34e632bb36150;hpb=5b655a9768f36c0f75a1c1a98426e5bb8802a5a8;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index ae715840eb..cacc3e4f1e 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -855,7 +855,9 @@ class Contact if (!empty($contact['batch']) && !empty($contact['term-date']) && ($contact['term-date'] > DBA::NULL_DATETIME)) { $fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false]; $condition = ['uid' => 0, 'network' => Protocol::FEDERATED, 'batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY]; - DBA::update('contact', $fields, $condition); + if (!DBA::exists('contact', array_merge($condition, $fields))) { + DBA::update('contact', $fields, $condition); + } } $condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], DBA::NULL_DATETIME]; @@ -1471,21 +1473,26 @@ class Contact /** * Return the photo path for a given contact array in the given size * - * @param array $contact contact array - * @param string $field Fieldname of the photo in the contact array - * @param string $size Size of the avatar picture - * @param string $avatar Avatar path that is displayed when no photo had been found + * @param array $contact contact array + * @param string $field Fieldname of the photo in the contact array + * @param string $size Size of the avatar picture + * @param string $avatar Avatar path that is displayed when no photo had been found + * @param bool $no_update Don't perfom an update if no cached avatar was found * @return string photo path */ - private static function getAvatarPath(array $contact, string $field, string $size, string $avatar) + private static function getAvatarPath(array $contact, string $field, string $size, string $avatar, $no_update = false) { if (!empty($contact)) { - $contact = self::checkAvatarCacheByArray($contact); + $contact = self::checkAvatarCacheByArray($contact, $no_update); if (!empty($contact[$field])) { $avatar = $contact[$field]; } } + if ($no_update && empty($avatar) && !empty($contact['avatar'])) { + $avatar = $contact['avatar']; + } + if (empty($avatar)) { $avatar = self::getDefaultAvatar([], $size); } @@ -1500,46 +1507,50 @@ class Contact /** * Return the photo path for a given contact array * - * @param array $contact Contact array - * @param string $avatar Avatar path that is displayed when no photo had been found + * @param array $contact Contact array + * @param string $avatar Avatar path that is displayed when no photo had been found + * @param bool $no_update Don't perfom an update if no cached avatar was found * @return string photo path */ - public static function getPhoto(array $contact, string $avatar = '') + public static function getPhoto(array $contact, string $avatar = '', bool $no_update = false) { - return self::getAvatarPath($contact, 'photo', Proxy::SIZE_SMALL, $avatar); + return self::getAvatarPath($contact, 'photo', Proxy::SIZE_SMALL, $avatar, $no_update); } /** * Return the photo path (thumb size) for a given contact array * - * @param array $contact Contact array - * @param string $avatar Avatar path that is displayed when no photo had been found + * @param array $contact Contact array + * @param string $avatar Avatar path that is displayed when no photo had been found + * @param bool $no_update Don't perfom an update if no cached avatar was found * @return string photo path */ - public static function getThumb(array $contact, string $avatar = '') + public static function getThumb(array $contact, string $avatar = '', bool $no_update = false) { - return self::getAvatarPath($contact, 'thumb', Proxy::SIZE_THUMB, $avatar); + return self::getAvatarPath($contact, 'thumb', Proxy::SIZE_THUMB, $avatar, $no_update); } /** * Return the photo path (micro size) for a given contact array * - * @param array $contact Contact array - * @param string $avatar Avatar path that is displayed when no photo had been found + * @param array $contact Contact array + * @param string $avatar Avatar path that is displayed when no photo had been found + * @param bool $no_update Don't perfom an update if no cached avatar was found * @return string photo path */ - public static function getMicro(array $contact, string $avatar = '') + public static function getMicro(array $contact, string $avatar = '', bool $no_update = false) { - return self::getAvatarPath($contact, 'micro', Proxy::SIZE_MICRO, $avatar); + return self::getAvatarPath($contact, 'micro', Proxy::SIZE_MICRO, $avatar, $no_update); } /** * Check the given contact array for avatar cache fields * * @param array $contact + * @param bool $no_update Don't perfom an update if no cached avatar was found * @return array contact array with avatar cache fields */ - private static function checkAvatarCacheByArray(array $contact) + private static function checkAvatarCacheByArray(array $contact, bool $no_update = false) { $update = false; $contact_fields = []; @@ -1553,7 +1564,7 @@ class Contact } } - if (!$update) { + if (!$update || $no_update) { return $contact; } @@ -1959,7 +1970,7 @@ class Contact } // If Probe::uri fails the network code will be different ("feed" or "unkn") - if (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network'])) { + if (($ret['network'] == Protocol::PHANTOM) || (($ret['network'] == Protocol::FEED) && ($ret['network'] != $contact['network']))) { self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated]); return false; }