Skip to content

Commit 2742ab5

Browse files
committed
Deprecated UserAction methods to enable/unban a user and enable avatar, cover photos and signature. Move this functionality to a command. Implement events that are triggered when this action is performed.
1 parent 610308d commit 2742ab5

19 files changed

+450
-97
lines changed

wcfsetup/install/files/lib/data/user/UserAction.class.php

Lines changed: 31 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@
2828
use wcf\system\user\command\BanUser;
2929
use wcf\system\user\command\DisableAvatar;
3030
use wcf\system\user\command\DisableSignature;
31+
use wcf\system\user\command\DisableUser;
32+
use wcf\system\user\command\EnableAvatar;
33+
use wcf\system\user\command\EnableCoverPhoto;
34+
use wcf\system\user\command\EnableSignature;
35+
use wcf\system\user\command\EnableUser;
36+
use wcf\system\user\command\UnbanUser;
3137
use wcf\system\user\group\assignment\UserGroupAssignmentHandler;
3238
use wcf\system\WCF;
33-
use wcf\util\UserRegistrationUtil;
3439

3540
/**
3641
* Executes user-related actions.
@@ -262,23 +267,18 @@ public function ban()
262267
* Unbans users.
263268
*
264269
* @return void
270+
*
271+
* @deprecated 6.3 use `UnbanUser`
265272
*/
266273
public function unban()
267274
{
268-
$conditionBuilder = new PreparedStatementConditionBuilder();
269-
$conditionBuilder->add('userID IN (?)', [$this->objectIDs]);
275+
if ($this->objects === []) {
276+
$this->readObjects();
277+
}
270278

271-
$sql = "UPDATE wcf1_user
272-
SET banned = ?,
273-
banExpires = ?
274-
" . $conditionBuilder;
275-
$statement = WCF::getDB()->prepare($sql);
276-
$statement->execute(
277-
\array_merge([
278-
0,
279-
0,
280-
], $conditionBuilder->getParameters())
281-
);
279+
foreach ($this->getObjects() as $userEditor) {
280+
(new UnbanUser($userEditor->getDecoratedObject()))();
281+
}
282282
}
283283

284284
/**
@@ -759,59 +759,18 @@ public function unconfirmEmail()
759759
* Enables users.
760760
*
761761
* @return void
762+
*
763+
* @deprecated 6.3 use `EnableUser`
762764
*/
763765
public function enable()
764766
{
765767
if (empty($this->objects)) {
766768
$this->readObjects();
767769
}
768770

769-
$data = [
770-
'activationCode' => 0,
771-
'blacklistMatches' => '',
772-
];
773-
774-
if (!((int)REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) {
775-
$data['emailConfirmed'] = null;
776-
}
777-
778-
$action = new self($this->objects, 'update', [
779-
'data' => $data,
780-
'removeGroups' => UserGroup::getGroupIDsByType([UserGroup::GUESTS]),
781-
]);
782-
$action->executeAction();
783-
$action = new self($this->objects, 'addToGroups', [
784-
'groups' => UserGroup::getGroupIDsByType([UserGroup::USERS]),
785-
'deleteOldGroups' => false,
786-
'addDefaultGroups' => false,
787-
]);
788-
$action->executeAction();
789-
790-
// send e-mail notification
791-
if (empty($this->parameters['skipNotification'])) {
792-
foreach ($this->getObjects() as $user) {
793-
$email = new Email();
794-
$email->setMessageID(\sprintf(
795-
'com.woltlab.wcf.adminActivation/%d/%d/%s',
796-
$user->userID,
797-
TIME_NOW,
798-
\bin2hex(\random_bytes(8))
799-
));
800-
$email->addRecipient(new UserMailbox($user->getDecoratedObject()));
801-
$email->setSubject($user->getLanguage()->getDynamicVariable('wcf.acp.user.activation.mail.subject'));
802-
$email->setBody(new MimePartFacade([
803-
new RecipientAwareTextMimePart('text/html', 'email_adminActivation'),
804-
new RecipientAwareTextMimePart('text/plain', 'email_adminActivation'),
805-
]));
806-
$email->send();
807-
}
808-
}
809-
810-
$userIDs = [];
811771
foreach ($this->getObjects() as $user) {
812-
$userIDs[] = $user->userID;
772+
(new EnableUser($user->getDecoratedObject(), $this->parameters['skipNotification'] ?? false))();
813773
}
814-
UserGroupAssignmentHandler::getInstance()->checkUsers($userIDs);
815774

816775
$this->unmarkItems();
817776
}
@@ -820,31 +779,18 @@ public function enable()
820779
* Disables users.
821780
*
822781
* @return void
782+
*
783+
* @deprecated 6.3 use `DisableUser`
823784
*/
824785
public function disable()
825786
{
826787
if (empty($this->objects)) {
827788
$this->readObjects();
828789
}
829790

830-
// We reset the activationCode (which indicates, that the user is not enabled) AND disable the email
831-
// confirm status, because if the user can enable himself by an email confirmation and we do not reset
832-
// the email confirmed status, the behavior is undefined, because a user exists, which is not enabled
833-
// but has a valid email address (Which doesn't usually happen).
834-
$action = new self($this->objects, 'update', [
835-
'data' => [
836-
'activationCode' => UserRegistrationUtil::getActivationCode(),
837-
'emailConfirmed' => Hex::encode(\random_bytes(20)),
838-
],
839-
'removeGroups' => UserGroup::getGroupIDsByType([UserGroup::USERS]),
840-
]);
841-
$action->executeAction();
842-
$action = new self($this->objects, 'addToGroups', [
843-
'groups' => UserGroup::getGroupIDsByType([UserGroup::GUESTS]),
844-
'deleteOldGroups' => false,
845-
'addDefaultGroups' => false,
846-
]);
847-
$action->executeAction();
791+
foreach ($this->getObjects() as $userEditor) {
792+
(new DisableUser($userEditor->getDecoratedObject()))();
793+
}
848794

849795
$this->unmarkItems();
850796
}
@@ -937,6 +883,8 @@ public function validateEnableSignature()
937883
* Enables the signature of the handled users.
938884
*
939885
* @return void
886+
*
887+
* @deprecated 6.3 use `EnableSignature`
940888
*/
941889
public function enableSignature()
942890
{
@@ -945,9 +893,7 @@ public function enableSignature()
945893
}
946894

947895
foreach ($this->getObjects() as $userEditor) {
948-
$userEditor->update([
949-
'disableSignature' => 0,
950-
]);
896+
(new EnableSignature($userEditor->getDecoratedObject()))();
951897
}
952898
}
953899

@@ -1057,6 +1003,8 @@ public function validateEnableAvatar()
10571003
* Enables the avatar of the handled users.
10581004
*
10591005
* @return void
1006+
*
1007+
* @deprecated 6.3 use `EnableAvatar`
10601008
*/
10611009
public function enableAvatar()
10621010
{
@@ -1065,9 +1013,7 @@ public function enableAvatar()
10651013
}
10661014

10671015
foreach ($this->getObjects() as $userEditor) {
1068-
$userEditor->update([
1069-
'disableAvatar' => 0,
1070-
]);
1016+
(new EnableAvatar($userEditor->getDecoratedObject()))();
10711017
}
10721018
}
10731019

@@ -1097,6 +1043,8 @@ public function validateEnableCoverPhoto()
10971043
*
10981044
* @return void
10991045
* @since 5.2
1046+
*
1047+
* @deprecated 6.3 use `EnableCoverPhoto`
11001048
*/
11011049
public function enableCoverPhoto()
11021050
{
@@ -1105,9 +1053,7 @@ public function enableCoverPhoto()
11051053
}
11061054

11071055
foreach ($this->getObjects() as $userEditor) {
1108-
$userEditor->update([
1109-
'disableCoverPhoto' => 0,
1110-
]);
1056+
(new EnableCoverPhoto($userEditor->getDecoratedObject()))();
11111057
}
11121058
}
11131059

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\user;
4+
5+
use wcf\data\user\User;
6+
use wcf\event\IPsr14Event;
7+
8+
/**
9+
* Indicates that a user's avatar has been enabled.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.3
15+
*/
16+
final class UserAvatarEnabled implements IPsr14Event
17+
{
18+
public function __construct(public readonly User $user)
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\user;
4+
5+
use wcf\data\user\User;
6+
use wcf\event\IPsr14Event;
7+
8+
/**
9+
* Indicates that a user's cover photo has been enabled.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.3
15+
*/
16+
final class UserCoverPhotoEnabled implements IPsr14Event
17+
{
18+
public function __construct(public readonly User $user)
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\user;
4+
5+
use wcf\data\user\User;
6+
use wcf\event\IPsr14Event;
7+
8+
/**
9+
* Indicates that a user has been disabled.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.3
15+
*/
16+
final class UserDisabled implements IPsr14Event
17+
{
18+
public function __construct(public readonly User $user)
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\user;
4+
5+
use wcf\data\user\User;
6+
use wcf\event\IPsr14Event;
7+
8+
/**
9+
* Indicates that a user has been enabled.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.3
15+
*/
16+
final class UserEnabled implements IPsr14Event
17+
{
18+
public function __construct(public readonly User $user)
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\user;
4+
5+
use wcf\data\user\User;
6+
use wcf\event\IPsr14Event;
7+
8+
/**
9+
* Indicates that a user's signature has been enabled.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.3
15+
*/
16+
final class UserSignatureEnabled implements IPsr14Event
17+
{
18+
public function __construct(public readonly User $user)
19+
{
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace wcf\event\user;
4+
5+
use wcf\data\user\User;
6+
use wcf\event\IPsr14Event;
7+
8+
/**
9+
* Indicates that a user has been unbanned.
10+
*
11+
* @author Olaf Braun
12+
* @copyright 2001-2025 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.3
15+
*/
16+
final class UserUnbanned implements IPsr14Event
17+
{
18+
public function __construct(public readonly User $user)
19+
{
20+
}
21+
}

wcfsetup/install/files/lib/system/endpoint/controller/core/users/DisableUser.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Psr\Http\Message\ServerRequestInterface;
88
use wcf\data\user\group\UserGroup;
99
use wcf\data\user\User;
10-
use wcf\data\user\UserAction;
1110
use wcf\http\Helper;
1211
use wcf\system\endpoint\IController;
1312
use wcf\system\endpoint\PostRequest;
@@ -34,7 +33,7 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
3433
$this->assertUserCanBeDisabled($user);
3534

3635
if (!$user->pendingActivation()) {
37-
(new UserAction([$user], 'disable'))->executeAction();
36+
(new \wcf\system\user\command\DisableUser($user))();
3837
}
3938

4039
return new JsonResponse([]);

wcfsetup/install/files/lib/system/endpoint/controller/core/users/EnableUser.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Psr\Http\Message\ServerRequestInterface;
88
use wcf\data\user\group\UserGroup;
99
use wcf\data\user\User;
10-
use wcf\data\user\UserAction;
1110
use wcf\http\Helper;
1211
use wcf\system\endpoint\IController;
1312
use wcf\system\endpoint\PostRequest;
@@ -34,7 +33,7 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
3433
$this->assertUserCanBeEnabled($user);
3534

3635
if ($user->pendingActivation()) {
37-
(new UserAction([$user], 'enable'))->executeAction();
36+
(new \wcf\system\user\command\EnableUser($user))();
3837
}
3938

4039
return new JsonResponse([]);

wcfsetup/install/files/lib/system/endpoint/controller/core/users/EnableUserAvatar.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use Psr\Http\Message\ServerRequestInterface;
88
use wcf\data\user\group\UserGroup;
99
use wcf\data\user\User;
10-
use wcf\data\user\UserAction;
1110
use wcf\http\Helper;
1211
use wcf\system\endpoint\IController;
1312
use wcf\system\endpoint\PostRequest;
1413
use wcf\system\exception\IllegalLinkException;
1514
use wcf\system\exception\PermissionDeniedException;
15+
use wcf\system\user\command\EnableAvatar;
1616
use wcf\system\WCF;
1717

1818
/**
@@ -34,7 +34,7 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
3434
$this->assertAvatarCanBeEnabled($user);
3535

3636
if ($user->disableAvatar) {
37-
(new UserAction([$user], 'enableAvatar'))->executeAction();
37+
(new EnableAvatar($user))();
3838
}
3939

4040
return new JsonResponse([]);

0 commit comments

Comments
 (0)