namespace wcf\system\worker;
+use wcf\data\file\FileEditor;
use wcf\data\reaction\type\ReactionTypeCache;
-use wcf\data\user\avatar\UserAvatar;
use wcf\data\user\avatar\UserAvatarEditor;
use wcf\data\user\avatar\UserAvatarList;
use wcf\data\user\cover\photo\DefaultUserCoverPhoto;
use wcf\data\user\UserProfileList;
use wcf\system\bbcode\BBCodeHandler;
use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\exception\SystemException;
use wcf\system\html\input\HtmlInputProcessor;
-use wcf\system\image\ImageHandler;
use wcf\system\user\storage\UserStorageHandler;
use wcf\system\WCF;
// update old/imported avatars
$avatarList = new UserAvatarList();
$avatarList->getConditionBuilder()->add('user_avatar.userID IN (?)', [$userIDs]);
- $avatarList->getConditionBuilder()->add(
- '(
- (user_avatar.width <> ? OR user_avatar.height <> ?)
- OR (user_avatar.hasWebP = ? AND user_avatar.avatarExtension <> ?)
- )',
- [
- UserAvatar::AVATAR_SIZE,
- UserAvatar::AVATAR_SIZE,
- 0,
- "gif",
- ]
- );
$avatarList->readObjects();
$resetAvatarCache = [];
+
+ $sql = "UPDATE wcf1_user
+ SET avatarFileID = ?
+ WHERE userID = ?";
+ $avatarUpdateStatement = WCF::getDB()->prepare($sql);
+
foreach ($avatarList as $avatar) {
$resetAvatarCache[] = $avatar->userID;
continue;
}
- $width = $avatar->width;
- $height = $avatar->height;
- if ($width != $height) {
- // make avatar quadratic
- $width = $height = \min($width, $height, UserAvatar::AVATAR_SIZE);
- $adapter = ImageHandler::getInstance()->getAdapter();
-
- try {
- $adapter->loadFile($avatar->getLocation());
- } catch (SystemException $e) {
- // broken image
- $editor->delete();
- continue;
- }
-
- $thumbnail = $adapter->createThumbnail($width, $height, false);
- $adapter->writeImage($thumbnail, $avatar->getLocation());
- // Clear thumbnail as soon as possible to free up the memory.
- $thumbnail = null;
- }
+ $file = FileEditor::createFromExistingFile(
+ $avatar->getLocation(),
+ $avatar->avatarName,
+ 'com.woltlab.wcf.user.avatar'
+ );
+ $editor->delete();
- if ($width != UserAvatar::AVATAR_SIZE || $height != UserAvatar::AVATAR_SIZE) {
- // resize avatar
- $adapter = ImageHandler::getInstance()->getAdapter();
-
- try {
- $adapter->loadFile($avatar->getLocation());
- } catch (SystemException $e) {
- // broken image
- $editor->delete();
- continue;
- }
-
- $adapter->resize(0, 0, $width, $height, UserAvatar::AVATAR_SIZE, UserAvatar::AVATAR_SIZE);
- $adapter->writeImage($adapter->getImage(), $avatar->getLocation());
- $width = $height = UserAvatar::AVATAR_SIZE;
+ if ($file === null) {
+ continue;
}
- $editor->createAvatarVariant();
-
- $editor->update([
- 'width' => $width,
- 'height' => $height,
+ $avatarUpdateStatement->execute([
+ $file->fileID,
+ $avatar->userID
]);
}