Fixed missing language version for embedded articles
authorMarcel Werk <burntime@woltlab.com>
Tue, 6 Jul 2021 11:08:46 +0000 (13:08 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 6 Jul 2021 11:08:46 +0000 (13:08 +0200)
wcfsetup/install/files/lib/system/message/embedded/object/ArticleMessageEmbeddedObjectHandler.class.php

index a7b808392beba3474d2898eaa2410998a45ab534..4d53b9fbdcffb05aa7201fac177eab18ac735339 100644 (file)
@@ -4,6 +4,8 @@ namespace wcf\system\message\embedded\object;
 
 use wcf\data\article\AccessibleArticleList;
 use wcf\data\article\Article;
+use wcf\data\article\content\ViewableArticleContentList;
+use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
 use wcf\system\html\input\HtmlInputProcessor;
 
 /**
@@ -36,11 +38,33 @@ class ArticleMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedO
      */
     public function loadObjects(array $objectIDs)
     {
-        $articleList = new AccessibleArticleList();
-        $articleList->getConditionBuilder()->add('article.articleID IN (?)', [$objectIDs]);
-        $articleList->readObjects();
+        $viewableArticles = ViewableArticleRuntimeCache::getInstance()->getObjects($objectIDs);
+        $contentLanguageID = MessageEmbeddedObjectManager::getInstance()->getContentLanguageID();
+        if ($contentLanguageID !== null) {
+            $articleIDs = [];
+            foreach ($viewableArticles as $article) {
+                if (
+                    $article !== null
+                    && $article->getArticleContent()->languageID
+                    && $article->getArticleContent()->languageID != $contentLanguageID
+                ) {
+                    $articleIDs[] = $article->articleID;
+                }
+            }
+
+            if (!empty($articleIDs)) {
+                $list = new ViewableArticleContentList();
+                $list->getConditionBuilder()->add("articleID IN (?)", [$articleIDs]);
+                $list->getConditionBuilder()->add("languageID = ?", [$contentLanguageID]);
+                $list->readObjects();
+
+                foreach ($list->getObjects() as $articleContent) {
+                    $viewableArticles[$articleContent->articleID]->setArticleContent($articleContent);
+                }
+            }
+        }
 
-        return $articleList->getObjects();
+        return $viewableArticles;
     }
 
     /**