From a6de08d675f00a7e2363f34e959e8d08bc65f771 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 8 Jul 2021 09:36:37 +0200 Subject: [PATCH] Fix recursively loading embedded objects in articles Close #4382 See 3af7b77d40ed93c95cebb22004ab745bf69683e2 --- .../article/ViewableArticleList.class.php | 19 ++++++++++++++++++ .../ViewableArticleContentList.class.php | 20 ++++++++++++++++++- ...icleMessageEmbeddedObjectHandler.class.php | 14 +++++++++---- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php b/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php index 293de4d2b2..096f9fa86d 100644 --- a/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php +++ b/wcfsetup/install/files/lib/data/article/ViewableArticleList.class.php @@ -37,6 +37,13 @@ class ViewableArticleList extends ArticleList */ protected $contentLoading = true; + /** + * enables/disables the loading of embedded objects in the article contents + * @var bool + * @since 5.4 + */ + protected $embeddedObjectLoading = true; + /** * @inheritDoc */ @@ -92,6 +99,7 @@ class ViewableArticleList extends ArticleList // get article content if ($this->contentLoading && !empty($this->objectIDs)) { $contentList = new ViewableArticleContentList(); + $contentList->enableEmbeddedObjectLoading($this->embeddedObjectLoading); $contentList->getConditionBuilder()->add('article_content.articleID IN (?)', [$this->objectIDs]); $contentList->getConditionBuilder()->add( '(article_content.languageID IS NULL OR article_content.languageID = ?)', @@ -128,4 +136,15 @@ class ViewableArticleList extends ArticleList { $this->contentLoading = $enable; } + + /** + * Enables/disables the loading of embedded objects in the article contents. + * + * @param bool $enable + * @since 5.4 + */ + public function enableEmbeddedObjectLoading(bool $enable = true): void + { + $this->embeddedObjectLoading = $enable; + } } diff --git a/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php b/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php index 56fa8fa174..670aa27469 100644 --- a/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php +++ b/wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php @@ -28,6 +28,13 @@ class ViewableArticleContentList extends ArticleContentList */ public $decoratorClassName = ViewableArticleContent::class; + /** + * enables/disables the loading of embedded objects in the article contents + * @var bool + * @since 5.4 + */ + protected $embeddedObjectLoading = true; + /** * @inheritDoc */ @@ -64,7 +71,7 @@ class ViewableArticleContentList extends ArticleContentList } // load embedded objects - if (!empty($embeddedObjectContentIDs)) { + if ($this->embeddedObjectLoading && !empty($embeddedObjectContentIDs)) { MessageEmbeddedObjectManager::getInstance()->loadObjects( 'com.woltlab.wcf.article.content', $embeddedObjectContentIDs, @@ -100,4 +107,15 @@ class ViewableArticleContentList extends ArticleContentList } } } + + /** + * Enables/disables the loading of embedded objects in the article contents. + * + * @param bool $enable + * @since 5.4 + */ + public function enableEmbeddedObjectLoading(bool $enable = true): void + { + $this->embeddedObjectLoading = $enable; + } } diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/ArticleMessageEmbeddedObjectHandler.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/ArticleMessageEmbeddedObjectHandler.class.php index 4d53b9fbdc..13381e4a4a 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/ArticleMessageEmbeddedObjectHandler.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/ArticleMessageEmbeddedObjectHandler.class.php @@ -38,11 +38,17 @@ class ArticleMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedO */ public function loadObjects(array $objectIDs) { - $viewableArticles = ViewableArticleRuntimeCache::getInstance()->getObjects($objectIDs); + // Do not use `ViewableArticleRuntimeCache` to avoid recursively loading embedded objects. + $articleList = new AccessibleArticleList(); + $articleList->enableEmbeddedObjectLoading(false); + $articleList->getConditionBuilder()->add('article.articleID IN (?)', [$objectIDs]); + $articleList->readObjects(); + $articles = $articleList->getObjects(); + $contentLanguageID = MessageEmbeddedObjectManager::getInstance()->getContentLanguageID(); if ($contentLanguageID !== null) { $articleIDs = []; - foreach ($viewableArticles as $article) { + foreach ($articles as $article) { if ( $article !== null && $article->getArticleContent()->languageID @@ -59,12 +65,12 @@ class ArticleMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedO $list->readObjects(); foreach ($list->getObjects() as $articleContent) { - $viewableArticles[$articleContent->articleID]->setArticleContent($articleContent); + $articles[$articleContent->articleID]->setArticleContent($articleContent); } } } - return $viewableArticles; + return $articles; } /** -- 2.20.1