From 1a563623423f69424ef34051c46f7d5a987cb1c0 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 6 Mar 2018 20:00:44 +0100 Subject: [PATCH] Activity events for article comments used a wrong id The `objectID` of a comment on an article references the articleContentID, but is was previously used as if it was the articleID. --- ...CommentResponseUserActivityEvent.class.php | 20 +++++++++++------- .../ArticleCommentUserActivityEvent.class.php | 21 ++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php index 11b667a6be..8d96d8a9d6 100644 --- a/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php @@ -45,15 +45,21 @@ class ArticleCommentResponseUserActivityEvent extends SingletonFactory implement } // fetch articles - $articleIDs = $articles = []; + $articleContentIDs = []; foreach ($comments as $comment) { - $articleIDs[] = $comment->objectID; + $articleContentIDs[] = $comment->objectID; } - if (!empty($articleIDs)) { + + $articles = $articleContentToArticle = []; + if (!empty($articleContentIDs)) { $articleList = new ViewableArticleList(); - $articleList->setObjectIDs($articleIDs); + $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$articleContentIDs]); $articleList->readObjects(); - $articles = $articleList->getObjects(); + foreach ($articleList as $article) { + $articles[$article->articleID] = $article; + + $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID; + } } // fetch users @@ -73,8 +79,8 @@ class ArticleCommentResponseUserActivityEvent extends SingletonFactory implement if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; $comment = $comments[$response->commentID]; - if (isset($articles[$comment->objectID]) && isset($users[$comment->userID])) { - $article = $articles[$comment->objectID]; + if (isset($articleContentToArticle[$comment->objectID]) && isset($users[$comment->userID])) { + $article = $articles[$articleContentToArticle[$comment->objectID]]; // check permissions if (!$article->canRead()) { diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php index 6fdf660d58..7b5bdb388c 100644 --- a/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php @@ -31,15 +31,21 @@ class ArticleCommentUserActivityEvent extends SingletonFactory implements IUserA $comments = $commentList->getObjects(); // fetch articles - $articleIDs = $articles = []; + $articleContentIDs = []; foreach ($comments as $comment) { - $articleIDs[] = $comment->objectID; + $articleContentIDs[] = $comment->objectID; } - if (!empty($articleIDs)) { + + $articles = $articleContentToArticle = []; + if (!empty($articleContentIDs)) { $articleList = new ViewableArticleList(); - $articleList->setObjectIDs($articleIDs); + $articleList->getConditionBuilder()->add("article.articleID IN (SELECT articleID FROM wcf".WCF_N."_article_content WHERE articleContentID IN (?))", [$articleContentIDs]); $articleList->readObjects(); - $articles = $articleList->getObjects(); + foreach ($articleList as $article) { + $articles[$article->articleID] = $article; + + $articleContentToArticle[$article->getArticleContent()->articleContentID] = $article->articleID; + } } // set message @@ -47,11 +53,12 @@ class ArticleCommentUserActivityEvent extends SingletonFactory implements IUserA if (isset($comments[$event->objectID])) { // short output $comment = $comments[$event->objectID]; - if (isset($articles[$comment->objectID])) { - $article = $articles[$comment->objectID]; + if (isset($articleContentToArticle[$comment->objectID])) { + $article = $articles[$articleContentToArticle[$comment->objectID]]; // check permissions if (!$article->canRead()) { + wcfDebug("nope"); continue; } $event->setIsAccessible(); -- 2.20.1