Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
->columns([
IntDatabaseTableColumn::create('templateGroupID'),
]),
PartialDatabaseTable::create('wcf1_user_activity_event')
->columns([
IntDatabaseTableColumn::create('userID'),
VarcharDatabaseTableColumn::create('username')
->length(255),
]),
PartialDatabaseTable::create('wcf1_acp_session_log')
->columns([
BinaryDatabaseTableColumn::create('sessionID')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function __invoke(): Article
$article->articleID,
null,
$article->userID,
$article->time
$article->time,
username: $article->username
);

new MarkArticleAsRead($article)();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(): void
->update();

$this->updateUserWatch($this->article);
$this->addUserActivity($this->article->articleID, $this->article->userID);
$this->addUserActivity($this->article);

if ($this->article->userID !== null) {
ArticleBuilder::incrementArticleCounter($this->article->userID, 1);
Expand All @@ -54,14 +54,15 @@ private function updateUserWatch(Article $article): void
);
}

private function addUserActivity(int $articleID, int $userID): void
private function addUserActivity(Article $article): void
{
UserActivityEventHandler::getInstance()->fireEvent(
'com.woltlab.wcf.article.recentActivityEvent',
$articleID,
$article->articleID,
null,
$userID,
\TIME_NOW
$article->userID,
\TIME_NOW,
username: $article->username
);
}
}
19 changes: 10 additions & 9 deletions wcfsetup/install/files/lib/command/article/UpdateArticle.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __invoke(): Article
{
$oldArticle = $this->builder->getObject();
$oldStatus = $oldArticle->publicationStatus;
$oldUserID = $oldArticle->userID;

// Capture the current content before it is overwritten so that the
// previous state can be stored as a version.
Expand Down Expand Up @@ -76,9 +75,8 @@ public function __invoke(): Article
$this->handlePublicationStatusChange($article, $oldStatus, $newStatus);
}

$newUserID = $this->builder->properties['userID'] ?? $oldUserID;
if ($newUserID !== $oldUserID) {
$this->updateActivityEventAuthor($article->articleID, (int)$newUserID);
if ($article->userID !== $oldArticle->userID || $article->username !== $oldArticle->username) {
$this->updateActivityEventAuthor($article);
}

EventHandler::getInstance()->fire(new ArticleUpdated($article, $this->builder));
Expand Down Expand Up @@ -108,7 +106,8 @@ private function handlePublicationStatusChange(Article $article, int $oldStatus,
$article->articleID,
null,
$article->userID,
$article->time
$article->time,
username: $article->username
);
} else {
UserNotificationHandler::getInstance()->removeNotifications(
Expand All @@ -122,17 +121,19 @@ private function handlePublicationStatusChange(Article $article, int $oldStatus,
}
}

private function updateActivityEventAuthor(int $articleID, int $userID): void
private function updateActivityEventAuthor(Article $article): void
{
$sql = "UPDATE wcf1_user_activity_event
SET userID = ?
SET userID = ?,
username = ?
WHERE objectTypeID = ?
AND objectID = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([
$userID,
$article->userID,
$article->userID === null ? $article->username : null,
UserActivityEventHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.article.recentActivityEvent'),
$articleID,
$article->articleID,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public function __invoke(): void
private function fireActivityEvent(): void
{
if (
$this->comment->userID !== null
&& UserActivityEventHandler::getInstance()->getObjectTypeID(
UserActivityEventHandler::getInstance()->getObjectTypeID(
$this->objectType->objectType . '.recentActivityEvent'
) !== null
) {
Expand All @@ -64,7 +63,8 @@ private function fireActivityEvent(): void
$this->comment->commentID,
null,
$this->comment->userID,
$this->comment->time
$this->comment->time,
username: $this->comment->username
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public function __invoke(): void
private function fireActivityEvent(): void
{
if (
$this->response->userID !== null
&& UserActivityEventHandler::getInstance()->getObjectTypeID(
UserActivityEventHandler::getInstance()->getObjectTypeID(
$this->objectType->objectType . '.response.recentActivityEvent'
) !== null
) {
Expand All @@ -75,7 +74,8 @@ private function fireActivityEvent(): void
$this->response->responseID,
null,
$this->response->userID,
$this->response->time
$this->response->time,
username: $this->response->username
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion wcfsetup/install/files/lib/command/user/Follow.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private function fireActivityEvent(): void
{
UserActivityEventHandler::getInstance()->fireEvent(
'com.woltlab.wcf.user.recentActivityEvent.follow',
$this->target->userID
$this->target->userID,
userID: $this->user->userID,
);
}

Expand Down
3 changes: 2 additions & 1 deletion wcfsetup/install/files/lib/command/user/Unfollow.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private function removeActivityEvent(): void
{
UserActivityEventHandler::getInstance()->removeEvent(
'com.woltlab.wcf.user.recentActivityEvent.follow',
$this->target->userID
$this->target->userID,
userID: $this->user->userID,
);
}

Expand Down
14 changes: 10 additions & 4 deletions wcfsetup/install/files/lib/data/article/ArticleAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public function create()
$article->articleID,
null,
$article->userID,
$article->time
$article->time,
username: $article->username
);
}

Expand Down Expand Up @@ -336,7 +337,8 @@ public function update()
$articleEditor->articleID,
null,
$this->parameters['data']['userID'] ?? $articleEditor->userID,
$this->parameters['data']['time'] ?? $articleEditor->time
$this->parameters['data']['time'] ?? $articleEditor->time,
username: $this->parameters['data']['username'] ?? $articleEditor->username
);
} else {
$resetArticleIDs[] = $articleEditor->articleID;
Expand All @@ -363,9 +365,10 @@ public function update()
}

// update author in recent activities
if (isset($this->parameters['data']['userID'])) {
if (\array_key_exists('userID', $this->parameters['data'] ?? [])) {
$sql = "UPDATE wcf1_user_activity_event
SET userID = ?
SET userID = ?,
username = ?
WHERE objectTypeID = ?
AND objectID = ?";
$statement = WCF::getDB()->prepare($sql);
Expand All @@ -374,6 +377,9 @@ public function update()
if ($articleEditor->userID !== $this->parameters['data']['userID']) {
$statement->execute([
$this->parameters['data']['userID'],
$this->parameters['data']['userID'] === null
? ($this->parameters['data']['username'] ?? $articleEditor->username)
: null,
UserActivityEventHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.article.recentActivityEvent'),
$articleEditor->articleID,
]);
Expand Down
10 changes: 6 additions & 4 deletions wcfsetup/install/files/lib/data/comment/CommentAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,14 @@ public function triggerPublication()
$this->commentProcessor->updateCounter($comment->objectID, 1);

// fire activity event
if ($comment->userID !== null && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.recentActivityEvent') !== null) {
if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.recentActivityEvent') !== null) {
UserActivityEventHandler::getInstance()->fireEvent(
$objectType->objectType . '.recentActivityEvent',
$comment->commentID,
null,
$comment->userID,
$comment->time
$comment->time,
username: $comment->username
);
}

Expand Down Expand Up @@ -627,13 +628,14 @@ public function triggerPublicationResponse()
$this->commentProcessor->updateCounter($comment->objectID, 1);

// fire activity event
if ($response->userID !== null && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent') !== null) {
if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent') !== null) {
UserActivityEventHandler::getInstance()->fireEvent(
$objectType->objectType . '.response.recentActivityEvent',
$response->responseID,
null,
$response->userID,
$response->time
$response->time,
username: $response->username
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* @property-read int $objectTypeID id of the `com.woltlab.wcf.user.recentActivityEvent` object type
* @property-read int $objectID id of the object the user activity event belongs to
* @property-read ?int $languageID id of the language of the related object or null if the object has no specific language
* @property-read int $userID id of the user who has triggered the user activity event
* @property-read ?int $userID id of the user who has triggered the user activity event or `null` if the event was triggered by a guest
* @property-read ?string $username name of the guest who has triggered the user activity event or `null` if the event was triggered by a registered user
* @property-read int $time timestamp at which the user activity event has been triggered
* @property-read mixed[] $additionalData array with additional data of the user activity event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ public function setUserProfile(UserProfile $userProfile)
public function getUserProfile()
{
if ($this->userProfile === null) {
$this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
if ($this->userID !== null) {
$this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
} else {
$this->userProfile = UserProfile::getGuestUserProfile($this->username ?? '');
}
}

return $this->userProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public function readObjects()
$userIDs = [];
$eventGroups = [];
foreach ($this->objects as $event) {
$userIDs[] = $event->userID;
if ($event->userID !== null) {
$userIDs[] = $event->userID;
}

if (!isset($eventGroups[$event->objectTypeID])) {
$objectType = UserActivityEventHandler::getInstance()->getObjectType($event->objectTypeID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function readData()

if (UserProfileHandler::getInstance()->getIgnoredUsers(UserIgnore::TYPE_HIDE_MESSAGES) !== []) {
$this->eventList->getConditionBuilder()->add(
"user_activity_event.userID NOT IN (?)",
"(user_activity_event.userID IS NULL OR user_activity_event.userID NOT IN (?))",
[UserProfileHandler::getInstance()->getIgnoredUsers(UserIgnore::TYPE_HIDE_MESSAGES)]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function readObjects()
);
} elseif (UserProfileHandler::getInstance()->getIgnoredUsers(UserIgnore::TYPE_HIDE_MESSAGES) !== []) {
$this->objectList->getConditionBuilder()->add(
"user_activity_event.userID NOT IN (?)",
"(user_activity_event.userID IS NULL OR user_activity_event.userID NOT IN (?))",
[UserProfileHandler::getInstance()->getIgnoredUsers(UserIgnore::TYPE_HIDE_MESSAGES)]
);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ public function getFilteredList()
);
} elseif (UserProfileHandler::getInstance()->getIgnoredUsers(UserIgnore::TYPE_HIDE_MESSAGES) !== []) {
$this->objectList->getConditionBuilder()->add(
"user_activity_event.userID NOT IN (?)",
"(user_activity_event.userID IS NULL OR user_activity_event.userID NOT IN (?))",
[UserProfileHandler::getInstance()->getIgnoredUsers(UserIgnore::TYPE_HIDE_MESSAGES)]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function prepare(array $events)
$comment = $this->comments[$response->commentID];
if (
isset($articleContentToArticle[$comment->objectID])
&& isset($this->commentAuthors[$comment->userID])
&& $this->getCommentAuthor($comment) !== null
) {
$article = $articles[$articleContentToArticle[$comment->objectID]];

Expand All @@ -67,7 +67,7 @@ public function prepare(array $events)
$event->setTitle(WCF::getLanguage()->getDynamicVariable(
'wcf.article.recentActivity.articleCommentResponse',
[
'commentAuthor' => $this->commentAuthors[$comment->userID],
'commentAuthor' => $this->getCommentAuthor($comment),
'commentID' => $comment->commentID,
'responseID' => $response->responseID,
'article' => $article,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function prepare(array $events)
$comment = $this->comments[$response->commentID];
if (
PageCache::getInstance()->getPage($comment->objectID) !== null
&& isset($this->commentAuthors[$comment->userID])
&& $this->getCommentAuthor($comment) !== null
) {
$page = PageCache::getInstance()->getPage($comment->objectID);

Expand All @@ -42,7 +42,7 @@ public function prepare(array $events)
$event->setIsAccessible();

$event->setTitle(WCF::getLanguage()->getDynamicVariable('wcf.page.recentActivity.pageCommentResponse', [
'commentAuthor' => $this->commentAuthors[$comment->userID],
'commentAuthor' => $this->getCommentAuthor($comment),
'commentID' => $comment->commentID,
'responseID' => $response->responseID,
'page' => $page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public function prepare(array $events)
if (isset($this->responses[$event->objectID])) {
$response = $this->responses[$event->objectID];
$comment = $this->comments[$response->commentID];
if (isset($users[$comment->objectID]) && isset($this->commentAuthors[$comment->userID])) {
if (isset($users[$comment->objectID]) && $this->getCommentAuthor($comment) !== null) {
if (!$users[$comment->objectID]->isProtected()) {
$event->setIsAccessible();

$event->setTitle(WCF::getLanguage()->getDynamicVariable(
'wcf.user.profile.recentActivity.profileCommentResponse',
[
'commentAuthor' => $this->commentAuthors[$comment->userID],
'commentAuthor' => $this->getCommentAuthor($comment),
'commentID' => $comment->commentID,
'responseID' => $response->responseID,
'user' => $users[$comment->objectID],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,28 @@ protected function readResponseData(array $events)

$userIDs = [];
foreach ($this->comments as $comment) {
$userIDs[] = $comment->userID;
if ($comment->userID !== null) {
$userIDs[] = $comment->userID;
}
$this->commentObjectIDs[] = $comment->objectID;
}
if ($userIDs !== []) {
$this->commentAuthors = \array_filter(UserProfileRuntimeCache::getInstance()->getObjects($userIDs));
}
}

/**
* Returns the user profile of the comment's author or a guest profile if
* the comment was written by a guest.
*
* @since 6.3
*/
protected function getCommentAuthor(Comment $comment): ?UserProfile
{
if ($comment->userID === null) {
return UserProfile::getGuestUserProfile($comment->username);
}

return $this->commentAuthors[$comment->userID] ?? null;
}
}
Loading
Loading