Merge pull request #10462 from annando/duplicate-avatars
Removal of duplicated photo entries for a contact
This commit is contained in:
commit
c0579bcad9
2 changed files with 28 additions and 3 deletions
|
@ -214,7 +214,7 @@ class Photo extends BaseModule
|
|||
If (($contact['uid'] != 0) && empty($contact['photo']) && empty($contact['avatar'])) {
|
||||
$contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo', 'xmpp', 'addr']);
|
||||
}
|
||||
if (!empty($contact['photo'])) {
|
||||
if (!empty($contact['photo']) && !empty($contact['avatar'])) {
|
||||
// Fetch photo directly
|
||||
$resourceid = MPhoto::ridFromURI($contact['photo']);
|
||||
if (!empty($resourceid)) {
|
||||
|
@ -223,7 +223,8 @@ class Photo extends BaseModule
|
|||
return $photo;
|
||||
}
|
||||
}
|
||||
$url = $contact['photo'];
|
||||
// We continue with the avatar link when the photo link is invalid
|
||||
$url = $contact['avatar'];
|
||||
} elseif (!empty($contact['avatar'])) {
|
||||
$url = $contact['avatar'];
|
||||
} elseif ($customsize <= Proxy::PIXEL_MICRO) {
|
||||
|
|
|
@ -58,6 +58,7 @@ class RemoveUnusedAvatars
|
|||
Logger::notice('Removal done', ['count' => $count, 'total' => $total]);
|
||||
|
||||
self::fixPhotoContacts();
|
||||
self::deleteDuplicates();
|
||||
}
|
||||
|
||||
private static function fixPhotoContacts()
|
||||
|
@ -67,7 +68,7 @@ class RemoveUnusedAvatars
|
|||
$updated1 = 0;
|
||||
$updated2 = 0;
|
||||
Logger::notice('Starting contact fix');
|
||||
$photos = DBA::select('photo', [], ["`uid` = ? AND `contact-id` IN (SELECT `id` FROM `contact` WHERE `uid` != ?)", 0, 0]);
|
||||
$photos = DBA::select('photo', [], ["`uid` = ? AND `contact-id` IN (SELECT `id` FROM `contact` WHERE `uid` != ?) AND `contact-id` != ? AND `scale` IN (?, ?, ?)", 0, 0, 0, 4, 5, 6]);
|
||||
while ($photo = DBA::fetch($photos)) {
|
||||
$total++;
|
||||
$photo_contact = Contact::getById($photo['contact-id']);
|
||||
|
@ -101,4 +102,27 @@ class RemoveUnusedAvatars
|
|||
DBA::close($photos);
|
||||
Logger::notice('Contact fix done', ['total' => $total, 'updated1' => $updated1, 'updated2' => $updated2, 'deleted' => $deleted]);
|
||||
}
|
||||
|
||||
private static function deleteDuplicates()
|
||||
{
|
||||
$size = [4 => 'photo', 5 => 'thumb', 6 => 'micro'];
|
||||
|
||||
$total = 0;
|
||||
$deleted = 0;
|
||||
Logger::notice('Starting duplicate removal');
|
||||
$photos = DBA::p("SELECT `photo`.`id`, `photo`.`uid`, `photo`.`scale`, `photo`.`album`, `photo`.`contact-id`, `photo`.`resource-id`, `contact`.`photo`, `contact`.`thumb`, `contact`.`micro` FROM `photo` INNER JOIN `contact` ON `contact`.`id` = `photo`.`contact-id` and `photo`.`contact-id` != ? AND `photo`.`scale` IN (?, ?, ?)", 0, 4, 5, 6);
|
||||
while ($photo = DBA::fetch($photos)) {
|
||||
$resource = Photo::ridFromURI($photo[$size[$photo['scale']]]);
|
||||
if ($resource != $photo['resource-id'] && !empty($resource)) {
|
||||
$total++;
|
||||
if (DBA::exists('photo', ['resource-id' => $resource, 'scale' => $photo['scale']])) {
|
||||
Logger::notice('Photo deleted', ['id' => $photo['id']]);
|
||||
Photo::delete(['id' => $photo['id']]);
|
||||
$deleted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
DBA::close($photos);
|
||||
Logger::notice('Duplicate removal done', ['total' => $total, 'deleted' => $deleted]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue