From f608dbd146f48878593e979968d2760437656a58 Mon Sep 17 00:00:00 2001 From: Olaf Braun Date: Fri, 23 Aug 2024 15:53:29 +0200 Subject: [PATCH] Add a migration description of how embedded objects should be loaded to quotes before they are added to the `MessageQuoteManager`. --- docs/migration/wsc60/php.md | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/docs/migration/wsc60/php.md b/docs/migration/wsc60/php.md index 2fc6731e..f7de6409 100644 --- a/docs/migration/wsc60/php.md +++ b/docs/migration/wsc60/php.md @@ -146,3 +146,55 @@ class FooBarCategoryEditForm extends FooBarCategoryAddForm { See [WoltLab/WCF#5657](https://github.com/WoltLab/WCF/pull/5657 ) for more details. + +## Loading embedded objects for quotes + +When saving a quote, it is necessary to load embedded objects before adding the quote to the `MessageQuoteManager`. +This is to ensure that the embedded objects are displayed correctly in the quote preview. + +```PHP +public class FooBarAction extends AbstractDatabaseObjectAction implements IMessageQuoteAction +{ + private function loadEmbeddedObjects(): void + { + if ($this->object->hasEmbeddedObjects) { + ObjectTypeCache::getInstance() + ->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'foo.bar.attachment') + ->getProcessor() + ->cacheObjects([$this->object->objectID]); + MessageEmbeddedObjectManager::getInstance()->loadObjects( + 'foo.bar.message', + [$this->object->objectID] + ); + } + } + + public function saveFullQuote() + { + $this->loadEmbeddedObjects(); + + $quoteID = MessageQuoteManager::getInstance()->addQuote( + 'foo.bar.message', + $this->object->parentObjectID, + $this->object->objectID, + $this->object->getExcerpt(), + $this->object->getMessage() + ); + … + } + + public function saveQuote() + { + $this->loadEmbeddedObjects(); + + $quoteID = MessageQuoteManager::getInstance()->addQuote( + 'foo.bar.message', + $this->object->parentObjectID, + $this->object->objectID, + $this->parameters['message'], + false + ); + … + } +} +``` -- 2.20.1