From a73313afff4a66dd702a83f653b3ea9aa9abe04f Mon Sep 17 00:00:00 2001 From: Marco Hermo Date: Fri, 12 Apr 2024 01:07:24 +1200 Subject: [PATCH] Indexer additional for published data --- src/Service/Indexer.php | 22 ++++++++++------------ tests/Fake/DocumentFake.php | 6 ------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/Service/Indexer.php b/src/Service/Indexer.php index 53492260..8cd10d26 100644 --- a/src/Service/Indexer.php +++ b/src/Service/Indexer.php @@ -6,6 +6,7 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injectable; use SilverStripe\ORM\DataObject; +use SilverStripe\SearchService\Interfaces\DataObjectDocumentInterface; use SilverStripe\SearchService\Interfaces\DependencyTracker; use SilverStripe\SearchService\Interfaces\DocumentAddHandler; use SilverStripe\SearchService\Interfaces\DocumentInterface; @@ -79,18 +80,15 @@ public function processNode(): void $document->onAddToSearchIndexes(DocumentAddHandler::BEFORE_ADD); } - // Making sure we get the Live version of the DataObject before indexing the document - Versioned::withVersionedMode(static function () use ($document): void { - Versioned::set_stage(Versioned::LIVE); - $dataObject = $document->getDataObject(); - - if (!$dataObject) { - return; - } - - $liveDataObject = DataObject::get($dataObject->ClassName)->byID($dataObject->ID); - $document->setDataObject($liveDataObject); - }); + if ($document instanceof DataObjectDocumentInterface) { + // Making sure we get the Live version of the DataObject before indexing the document + Versioned::withVersionedMode(static function () use ($document): void { + Versioned::set_stage(Versioned::LIVE); + $dataObject = $document->getDataObject(); + $liveDataObject = DataObject::get($dataObject->ClassName)->byID($dataObject->ID); + $document->setDataObject($liveDataObject); + }); + } $toUpdate[] = $document; } else { diff --git a/tests/Fake/DocumentFake.php b/tests/Fake/DocumentFake.php index ca21fa6c..b033ffd6 100644 --- a/tests/Fake/DocumentFake.php +++ b/tests/Fake/DocumentFake.php @@ -2,7 +2,6 @@ namespace SilverStripe\SearchService\Tests\Fake; -use SilverStripe\ORM\DataObject; use SilverStripe\SearchService\Interfaces\DependencyTracker; use SilverStripe\SearchService\Interfaces\DocumentInterface; @@ -56,9 +55,4 @@ public function getDependentDocuments(): array return $this->dependentDocuments; } - public function getDataObject(): ?DataObject - { - return null; - } - }