Skip to content

Commit

Permalink
Indexer additional for published data
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hermo committed Apr 11, 2024
1 parent de32cd3 commit a73313a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
22 changes: 10 additions & 12 deletions src/Service/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions tests/Fake/DocumentFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SilverStripe\SearchService\Tests\Fake;

use SilverStripe\ORM\DataObject;
use SilverStripe\SearchService\Interfaces\DependencyTracker;
use SilverStripe\SearchService\Interfaces\DocumentInterface;

Expand Down Expand Up @@ -56,9 +55,4 @@ public function getDependentDocuments(): array
return $this->dependentDocuments;
}

public function getDataObject(): ?DataObject
{
return null;
}

}

0 comments on commit a73313a

Please sign in to comment.