From 6807468ed21c5c3faf4ced03f37e12991fe6fe09 Mon Sep 17 00:00:00 2001 From: berliner Date: Wed, 20 Nov 2024 11:50:58 +0100 Subject: [PATCH] HPC-9890: Don't request rendered content during migrations --- .../src/ContentManager/ArticleManager.php | 6 +++--- .../RemoteSourceBaseHpcContentModule.php | 16 ++++++++-------- .../src/RemoteSource/RemoteSourceInterface.php | 8 ++++++-- .../Plugin/RemoteSource/HpcContentModuleTest.php | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/html/modules/custom/ghi_content/src/ContentManager/ArticleManager.php b/html/modules/custom/ghi_content/src/ContentManager/ArticleManager.php index 6491b26f2..81ffe0ec0 100644 --- a/html/modules/custom/ghi_content/src/ContentManager/ArticleManager.php +++ b/html/modules/custom/ghi_content/src/ContentManager/ArticleManager.php @@ -67,7 +67,7 @@ public function loadNodeForRemoteContent(RemoteContentInterface $content) { /** * {@inheritdoc} */ - public function loadRemoteContentForNode(NodeInterface $node, $refresh = FALSE) { + public function loadRemoteContentForNode(NodeInterface $node, $refresh = FALSE, $rendered = TRUE) { $remote_field = $this->getRemoteFieldName(); if (!$node->hasField($remote_field)) { return; @@ -81,7 +81,7 @@ public function loadRemoteContentForNode(NodeInterface $node, $refresh = FALSE) if ($refresh) { $remote_source_instance->disableCache(); } - return $remote_source_instance->getArticle($article_id); + return $remote_source_instance->getArticle($article_id, $rendered); } /** @@ -172,7 +172,7 @@ protected function getMigration(NodeInterface $node) { */ public function updateNodeFromRemote(NodeInterface $node, $dry_run = FALSE, $reset = FALSE) { $remote_field = self::REMOTE_ARTICLE_FIELD; - $article = $this->loadRemoteContentForNode($node, TRUE); + $article = $this->loadRemoteContentForNode($node, TRUE, FALSE); if (!$article) { return; } diff --git a/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php b/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php index ea6941fcb..07b35e254 100644 --- a/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php +++ b/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceBaseHpcContentModule.php @@ -88,7 +88,7 @@ public function getDocument($id) { /** * {@inheritdoc} */ - public function getArticle($id) { + public function getArticle($id, $rendered = TRUE) { $fields = [ 'id', 'title', @@ -103,15 +103,15 @@ public function getArticle($id) { 'title', 'tags', ]; - $fields['content'] = [ + $fields['content'] = array_filter([ 'id', 'uuid', 'type', 'typeLabel', 'promoted', - 'rendered', + $rendered ? 'rendered' : NULL, 'configuration', - ]; + ]); $fields['image'] = [ 'credits', 'imageUrl', @@ -127,16 +127,16 @@ public function getArticle($id) { /** * {@inheritdoc} */ - public function getParagraph($id) { - $fields = [ + public function getParagraph($id, $rendered = TRUE) { + $fields = array_filter([ 'id', 'uuid', 'type', 'typeLabel', 'promoted', - 'rendered', + $rendered ? 'rendered' : NULL, 'configuration', - ]; + ]); $paragraph_data = $this->fetchData('paragraph', ['id' => $id], $fields); return new RemoteParagraph($paragraph_data, $this); } diff --git a/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceInterface.php b/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceInterface.php index 2af1957dc..45824d118 100644 --- a/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceInterface.php +++ b/html/modules/custom/ghi_content/src/RemoteSource/RemoteSourceInterface.php @@ -63,11 +63,13 @@ public function searchDocumentsByTitle($title); * * @param int $id * The id of the article on the remote. + * @param bool $rendered + * Allow to switch off rendering. * * @return \Drupal\ghi_content\RemoteContent\RemoteArticleInterface * The article object. */ - public function getArticle($id); + public function getArticle($id, $rendered = TRUE); /** * Search articles by title. @@ -85,11 +87,13 @@ public function searchArticlesByTitle($title); * * @param int $id * The id of the paragraph on the remote. + * @param bool $rendered + * Allow to switch off rendering. * * @return \Drupal\ghi_content\RemoteContent\RemoteParagraphInterface * The result object. */ - public function getParagraph($id); + public function getParagraph($id, $rendered = TRUE); /** * Issue a query against a remote source. diff --git a/html/modules/custom/ghi_content/tests/modules/ghi_content_test/src/Plugin/RemoteSource/HpcContentModuleTest.php b/html/modules/custom/ghi_content/tests/modules/ghi_content_test/src/Plugin/RemoteSource/HpcContentModuleTest.php index 68c411c2f..f7c884645 100644 --- a/html/modules/custom/ghi_content/tests/modules/ghi_content_test/src/Plugin/RemoteSource/HpcContentModuleTest.php +++ b/html/modules/custom/ghi_content/tests/modules/ghi_content_test/src/Plugin/RemoteSource/HpcContentModuleTest.php @@ -50,7 +50,7 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function getArticle($id) { + public function getArticle($id, $rendered = TRUE) { $json = $this->getFixture('article', $id); return $json->article ? new RemoteArticle($json->article, $this) : NULL; } @@ -66,7 +66,7 @@ public function getArticleTitle($id) { /** * {@inheritdoc} */ - public function getParagraph($id) { + public function getParagraph($id, $rendered = TRUE) { // @todo Implement this. return (object) []; }