From d785e06dc69e5f4c691642293825ecfcb03c4f75 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 7 Nov 2024 13:32:02 +0100 Subject: [PATCH] Avatar is now no longer saved in `UserEditForm` Use `File` as user avatar --- .../install/files/acp/templates/userAdd.tpl | 46 ++++----------- .../files/lib/acp/form/UserEditForm.class.php | 57 ++----------------- 2 files changed, 15 insertions(+), 88 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/userAdd.tpl b/wcfsetup/install/files/acp/templates/userAdd.tpl index 62ab6118f6..1fdee9563b 100644 --- a/wcfsetup/install/files/acp/templates/userAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userAdd.tpl @@ -600,32 +600,23 @@

{lang}wcf.user.avatar{/lang}

-
+
- -
-
- -
-
{if $avatarType == 'custom' && $userAvatar !== null} - {@$userAvatar->getImageTag(96)} + {else} {/if} -
-
- - - {* placeholder for upload button: *} -
+
+
- {if $errorType[customAvatar]|isset} - - {if $errorType[customAvatar] == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} +
+
+
+
@@ -695,23 +686,6 @@ {/if} - - - - {event name='avatarFieldsets'} diff --git a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php index c2aca3f0f0..cdbc950f17 100755 --- a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php @@ -2,9 +2,8 @@ namespace wcf\acp\form; +use wcf\data\file\File; use wcf\data\style\Style; -use wcf\data\user\avatar\UserAvatar; -use wcf\data\user\avatar\UserAvatarAction; use wcf\data\user\cover\photo\UserCoverPhoto; use wcf\data\user\group\UserGroup; use wcf\data\user\User; @@ -76,9 +75,8 @@ class UserEditForm extends UserAddForm /** * user avatar object - * @var UserAvatar */ - public $userAvatar; + public ?File $userAvatar = null; /** * avatar type @@ -222,9 +220,6 @@ class UserEditForm extends UserAddForm } } - if (isset($_POST['avatarType'])) { - $this->avatarType = $_POST['avatarType']; - } if (isset($_POST['styleID'])) { $this->styleID = \intval($_POST['styleID']); } @@ -294,8 +289,8 @@ class UserEditForm extends UserAddForm parent::readData(); // get the avatar object - if ($this->avatarType == 'custom' && $this->user->avatarID) { - $this->userAvatar = new UserAvatar($this->user->avatarID); + if ($this->avatarType == 'custom' && $this->user->avatarFileID) { + $this->userAvatar = new File($this->user->avatarFileID); } // get the user cover photo object @@ -348,7 +343,7 @@ class UserEditForm extends UserAddForm $this->disableCoverPhotoReason = $this->user->disableCoverPhotoReason; $this->disableCoverPhotoExpires = $this->user->disableCoverPhotoExpires; - if ($this->user->avatarID) { + if ($this->user->avatarFileID) { $this->avatarType = 'custom'; } @@ -397,24 +392,6 @@ class UserEditForm extends UserAddForm $this->htmlInputProcessor->setObjectID($this->userID); MessageEmbeddedObjectManager::getInstance()->registerObjects($this->htmlInputProcessor); - // handle avatar - if ($this->avatarType != 'custom') { - // delete custom avatar - if ($this->user->avatarID) { - $action = new UserAvatarAction([$this->user->avatarID], 'delete'); - $action->executeAction(); - } - } - - $avatarData = []; - if ($this->avatarType === 'none') { - $avatarData = [ - 'avatarID' => null, - ]; - } - - $this->additionalFields = \array_merge($this->additionalFields, $avatarData); - if ($this->disconnect3rdParty) { $this->additionalFields['authData'] = ''; } @@ -585,28 +562,6 @@ class UserEditForm extends UserAddForm } } - /** - * Validates the user avatar. - */ - protected function validateAvatar() - { - if ($this->avatarType != 'custom') { - $this->avatarType = 'none'; - } - - try { - switch ($this->avatarType) { - case 'custom': - if (!$this->user->avatarID) { - throw new UserInputException('customAvatar'); - } - break; - } - } catch (UserInputException $e) { - $this->errorType[$e->getField()] = $e->getType(); - } - } - /** * @inheritDoc */ @@ -620,8 +575,6 @@ class UserEditForm extends UserAddForm } } - $this->validateAvatar(); - parent::validate(); if (!isset($this->availableStyles[$this->styleID])) { -- 2.20.1