diff --git a/src/DataObject/DataObjectDocument.php b/src/DataObject/DataObjectDocument.php index 7ba0fca..0f0890f 100644 --- a/src/DataObject/DataObjectDocument.php +++ b/src/DataObject/DataObjectDocument.php @@ -125,18 +125,22 @@ public function shouldIndex(): bool // If an anonymous user can't view it $isPublic = Member::actAs(null, static function () use ($dataObject) { - // Need to make sure that the version of the DataObject that we access is always the LIVE version - return Versioned::withVersionedMode(static function () use ($dataObject): bool { - Versioned::set_stage(Versioned::LIVE); + if ($dataObject->hasExtension(Versioned::class)) { + // Need to make sure that the version of the DataObject that we access is always the LIVE version + return Versioned::withVersionedMode(static function () use ($dataObject): bool { + Versioned::set_stage(Versioned::LIVE); - $liveDataObject = DataObject::get($dataObject->ClassName)->byID($dataObject->ID); + $liveDataObject = DataObject::get($dataObject->ClassName)->byID($dataObject->ID); - if (!$liveDataObject || !$liveDataObject->exists()) { - return false; - } + if (!$liveDataObject || !$liveDataObject->exists()) { + return false; + } - return $liveDataObject->canView(); - }); + return $liveDataObject->canView(); + }); + } + + return $dataObject->canView(); }); if (!$isPublic) { diff --git a/src/Extensions/SearchServiceExtension.php b/src/Extensions/SearchServiceExtension.php index e7d148c..63f8cb0 100644 --- a/src/Extensions/SearchServiceExtension.php +++ b/src/Extensions/SearchServiceExtension.php @@ -115,6 +115,21 @@ public function onAfterPublish(): void $this->owner->addToIndexes(); } + /** + * When saving an un-versioned DataObject, push this data to Indexer. + * The data which is sent to search is the rendered template from the front end + * + * @throws Exception + */ + public function onAfterWrite(): void + { + if ($this->owner->hasExtension(Versioned::class)) { + return; + } + + $this->owner->addToIndexes(); + } + /** * When unpublishing this item, remove from search */