Properly unlink all old avatars when deleting/uploading a new

We're also now using $config['image']['jpegquality'] to determine the
quality setting for resized images.

To set Avatar max size, adjust $config['avatar']['maxsize']

The getAvatar call now throws exceptions too. Related changes applied.
Now let's move Profile->avatarUrl to the Avatar class!
This commit is contained in:
Mikael Nordfeldth
2013-10-01 11:37:59 +02:00
parent a7e748479c
commit b0dfc70a54
47 changed files with 219 additions and 335 deletions

View File

@@ -341,7 +341,14 @@ class TwitterImport
$newname = 'Twitter_' . $twitter_user->id . '_' . basename($twitter_user->profile_image_url);
$oldname = $profile->getAvatar(48)->filename;
try {
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
$oldname = $avatar->filename;
unset($avatar);
} catch (Exception $e) {
$oldname = null;
}
if ($newname != $oldname) {
common_debug($this->name() . ' - Avatar for Twitter user ' .
@@ -351,7 +358,7 @@ class TwitterImport
$this->updateAvatars($twitter_user, $profile);
}
if ($this->missingAvatarFile($profile)) {
if (Avatar::hasOriginal($profile)) {
common_debug($this->name() . ' - Twitter user ' .
$profile->nickname .
' is missing one or more local avatars.');
@@ -382,17 +389,6 @@ class TwitterImport
}
}
function missingAvatarFile($profile) {
foreach (array(24, 48, 73) as $size) {
$filename = $profile->getAvatar($size)->filename;
$avatarpath = Avatar::path($filename);
if (file_exists($avatarpath) == FALSE) {
return true;
}
}
return false;
}
function getMediatype($ext)
{
$mediatype = null;
@@ -447,13 +443,7 @@ class TwitterImport
return;
}
$sizes = array('mini' => 24, 'normal' => 48, 'bigger' => 73);
$avatar = $profile->getAvatar($sizes[$size]);
// Delete the avatar, if present
if ($avatar) {
$avatar->delete();
}
Avatar::deleteFromProfile($profile);
$this->newAvatar($profile->id, $size, $mediatype, $filename);
}