- if ($update) {
- $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
- if ($photos) {
- $fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()];
- DBA::update('contact', $fields, ['id' => $cid]);
- } elseif (empty($contact['avatar'])) {
- // Ensure that the avatar field is set
- DBA::update('contact', ['avatar' => $avatar], ['id' => $cid]);
- Logger::info('Failed profile import', ['id' => $cid, 'force' => $force, 'avatar' => $avatar, 'contact' => $contact]);
+ if (!$update) {
+ return;
+ }
+
+ $cids = [];
+ $uids = [];
+ if (($uid == 0) && !in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
+ // Collect all user contacts of the given public contact
+ $personal_contacts = DBA::select('contact', ['id', 'uid'],
+ ["`nurl` = ? AND `id` != ? AND NOT `self`", $contact['nurl'], $cid]);
+ while ($personal_contact = DBA::fetch($personal_contacts)) {
+ $cids[] = $personal_contact['id'];
+ $uids[] = $personal_contact['uid'];
+ }
+ DBA::close($personal_contacts);
+
+ if (!empty($cids)) {
+ // Delete possibly existing cached user contact avatars
+ Photo::delete(['uid' => $uids, 'contact-id' => $cids, 'album' => Photo::CONTACT_PHOTOS]);