Activity events for article comments used a wrong id
authorAlexander Ebert <ebert@woltlab.com>
Tue, 6 Mar 2018 19:00:44 +0000 (20:00 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 6 Mar 2018 19:00:44 +0000 (20:00 +0100)
The `objectID` of a comment on an article references the
articleContentID, but is was previously used as if it was the articleID.

wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentResponseUserActivityEvent.class.php
wcfsetup/install/files/lib/system/user/activity/event/ArticleCommentUserActivityEvent.class.php

index 11b667a6be30ce21d1df3895d9d454598d42d774..8d96d8a9d6bb74dd60f9e0e1c79595eb72304a5f 100644 (file)
@@ -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()) {
index 6fdf660d58178607f982c16940b9bb5855d7a7a5..7b5bdb388c621f8ab55a88b9bf7aa85b3831ad1a 100644 (file)
@@ -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();