From: Matthias Schmidt Date: Sun, 27 Mar 2016 06:25:38 +0000 (+0200) Subject: Add UserProfile::getGuestUserProfile() X-Git-Tag: 3.0.0_Beta_1~1286^2~25 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5266fbf1ecca6f3d761291f4aa66e299a0730fb7;p=GitHub%2FWoltLab%2FWCF.git Add UserProfile::getGuestUserProfile() --- diff --git a/CHANGELOG.md b/CHANGELOG.md index ef86f01b07..b05c294f9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,8 @@ * `wcf\system\event\listener\AbstractUserMergeListener` added. * Notice texts support `{$username}` and `{$email}` placeholders. * Notifications for comments in moderation. -* Continuous numeration of edit history version in template. +* Continuous numeration of edit history version in template. +* `\wcf\data\user\UserProfile::getGuestUserProfile()` added. #### New Traits diff --git a/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php b/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php index 544b43a4a6..a4fd6e32a0 100644 --- a/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php +++ b/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php @@ -1,7 +1,6 @@ userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID); } else { - $this->userProfile = new UserProfile(new User(null, [ - 'username' => $this->username - ])); + $this->userProfile = UserProfile::getGuestUserProfile($this->username); } } diff --git a/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php b/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php index 34d749556b..6e611ed042 100644 --- a/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php +++ b/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php @@ -1,6 +1,5 @@ userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID); } else { - $this->userProfile = new UserProfile(new User(null, [ - 'username' => $this->username - ])); + $this->userProfile = UserProfile::getGuestUserProfile($this->username); } } diff --git a/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php b/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php index b4eef2f3bb..dec2dccfcb 100644 --- a/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php @@ -1,6 +1,5 @@ userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID); } else { - $this->userProfile = new UserProfile(new User(null, array( - 'username' => $this->username - ))); + $this->userProfile = UserProfile::getGuestUserProfile($this->username); } } diff --git a/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php b/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php index 507cabfaf3..18c4d34ccc 100644 --- a/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php @@ -1,6 +1,5 @@ userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID); } else { - $this->userProfile = new UserProfile(new User(null, [ - 'username' => $this->username - ])); + $this->userProfile = UserProfile::getGuestUserProfile($this->username); } } diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index 68efae2148..a0d07996e3 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -791,4 +791,18 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider return ''.StringUtil::encodeHtml($this->username).''; } + + /** + * Returns an "empty" user profile object for a guest with the given username. + * + * Such objects can also be used in situations where the relevant user has been deleted + * but their original username is still known. + * + * @param string $username + * @return UserProfile + * @since 2.2 + */ + public static function getGuestUserProfile($username) { + return new UserProfile(new User(null, ['username' => $username])); + } } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentResponseUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentResponseUserNotificationEvent.class.php index 5c75ad2f44..eecac0d9c1 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentResponseUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentResponseUserNotificationEvent.class.php @@ -2,7 +2,6 @@ namespace wcf\system\user\notification\event; use wcf\data\moderation\queue\ViewableModerationQueue; use wcf\data\object\type\ObjectTypeCache; -use wcf\data\user\User; use wcf\data\user\UserProfile; use wcf\system\cache\runtime\CommentRuntimeCache; use wcf\system\cache\runtime\UserProfileRuntimeCache; @@ -82,9 +81,7 @@ class ModerationQueueCommentResponseUserNotificationEvent extends AbstractShared $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID); } else { - $commentAuthor = new UserProfile(new User(null, [ - 'username' => $comment->username - ])); + $commentAuthor = UserProfile::getGuestUserProfile($comment->username); } return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.mail', [ @@ -134,9 +131,7 @@ class ModerationQueueCommentResponseUserNotificationEvent extends AbstractShared $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID); } else { - $commentAuthor = new UserProfile(new User(null, [ - 'username' => $comment->username - ])); + $commentAuthor = UserProfile::getGuestUserProfile($comment->username); } return $this->getLanguage()->getDynamicVariable($this->getLanguageItemPrefix().'.commentResponse.message', [ diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php index da1c68cfee..3d710690db 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php @@ -56,9 +56,7 @@ class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractShare $commentAuthor = UserProfileRuntimeCache::getInstance()->getObject($comment->userID); } else { - $commentAuthor = new UserProfile(new User(null, [ - 'username' => $comment->username - ])); + $commentAuthor = UserProfile::getGuestUserProfile($comment->username); } $authors = $this->getAuthors();