Merge pull request #8089 from mexon/mat/repair-contact-photo
updateAvatar automatically repairs avatars when photos are deleted
This commit is contained in:
commit
4e3849c18b
3 changed files with 34 additions and 13 deletions
|
@ -1896,6 +1896,14 @@ class Contact
|
||||||
$data = [$contact["photo"], $contact["thumb"], $contact["micro"]];
|
$data = [$contact["photo"], $contact["thumb"], $contact["micro"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($data as $image_uri) {
|
||||||
|
$image_rid = Photo::ridFromURI($image_uri);
|
||||||
|
if ($image_rid && !Photo::exists(['resource-id' => $image_rid, 'uid' => $uid])) {
|
||||||
|
Logger::info('Regenerating avatar', ['contact uid' => $uid, 'cid' => $cid, 'missing photo' => $image_rid, 'avatar' => $contact['avatar']]);
|
||||||
|
$force = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (($contact["avatar"] != $avatar) || $force) {
|
if (($contact["avatar"] != $avatar) || $force) {
|
||||||
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
|
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
|
||||||
|
|
||||||
|
|
|
@ -215,12 +215,10 @@ class Mail
|
||||||
$images = $match[1];
|
$images = $match[1];
|
||||||
if (count($images)) {
|
if (count($images)) {
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
if (!stristr($image, DI::baseUrl() . '/photo/')) {
|
$image_rid = Photo::ridFromURI($image);
|
||||||
continue;
|
if (!empty($image_rid)) {
|
||||||
|
Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_rid, 'album' => 'Wall Photos', 'uid' => local_user()]);
|
||||||
}
|
}
|
||||||
$image_uri = substr($image, strrpos($image, '/') + 1);
|
|
||||||
$image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
|
|
||||||
Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_uri, 'album' => 'Wall Photos', 'uid' => local_user()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -590,6 +590,25 @@ class Photo
|
||||||
return System::createGUID(32, false);
|
return System::createGUID(32, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the rid from a local photo URI
|
||||||
|
*
|
||||||
|
* @param string $image_uri The URI of the photo
|
||||||
|
* @return string The rid of the photo, or an empty string if the URI is not local
|
||||||
|
*/
|
||||||
|
public static function ridFromURI(string $image_uri)
|
||||||
|
{
|
||||||
|
if (!stristr($image_uri, DI::baseUrl() . '/photo/')) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$image_uri = substr($image_uri, strrpos($image_uri, '/') + 1);
|
||||||
|
$image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
|
||||||
|
if (!strlen($image_uri)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return $image_uri;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes photo permissions that had been embedded in a post
|
* Changes photo permissions that had been embedded in a post
|
||||||
*
|
*
|
||||||
|
@ -616,12 +635,8 @@ class Photo
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
if (!stristr($image, DI::baseUrl() . '/photo/')) {
|
$image_rid = self::ridFromURI($image);
|
||||||
continue;
|
if (empty($image_rid)) {
|
||||||
}
|
|
||||||
$image_uri = substr($image,strrpos($image,'/') + 1);
|
|
||||||
$image_uri = substr($image_uri,0, strpos($image_uri,'-'));
|
|
||||||
if (!strlen($image_uri)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,7 +645,7 @@ class Photo
|
||||||
|
|
||||||
$condition = [
|
$condition = [
|
||||||
'allow_cid' => $srch, 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '',
|
'allow_cid' => $srch, 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '',
|
||||||
'resource-id' => $image_uri, 'uid' => $uid
|
'resource-id' => $image_rid, 'uid' => $uid
|
||||||
];
|
];
|
||||||
if (!Photo::exists($condition)) {
|
if (!Photo::exists($condition)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -640,7 +655,7 @@ class Photo
|
||||||
|
|
||||||
$fields = ['allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
|
$fields = ['allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
|
||||||
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny];
|
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny];
|
||||||
$condition = ['resource-id' => $image_uri, 'uid' => $uid];
|
$condition = ['resource-id' => $image_rid, 'uid' => $uid];
|
||||||
Logger::info('Set permissions', ['condition' => $condition, 'permissions' => $fields]);
|
Logger::info('Set permissions', ['condition' => $condition, 'permissions' => $fields]);
|
||||||
Photo::update($fields, $condition);
|
Photo::update($fields, $condition);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue