Skip to content

Commit

Permalink
add condition to check if parent exists
Browse files Browse the repository at this point in the history
ebakernz committed Feb 12, 2023
1 parent 6a9e821 commit a9e6647
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ElementalSearchExtension.php
Original file line number Diff line number Diff line change
@@ -37,10 +37,12 @@ public function onAfterUnpublish()
public function updateSearchContent()
{
$parent = $this->getOwner()->getPage();
//Even though we have the parent page. Lets always get the "live" version. This is so when we update the search content we are not indexing draft/unpublished content
$liveParentPage = Versioned::get_by_stage($parent->ClassName, Versioned::LIVE)->byID($parent->ID);
if ($liveParentPage && $liveParentPage->hasExtension(SiteTreeSearchExtension::class)) {
$liveParentPage->updateSearchContent();
if ($parent) {
//Even though we have the parent page. Lets always get the "live" version. This is so when we update the search content we are not indexing draft/unpublished content
$liveParentPage = Versioned::get_by_stage($parent->ClassName, Versioned::LIVE)->byID($parent->ID);
if ($liveParentPage && $liveParentPage->hasExtension(SiteTreeSearchExtension::class)) {
$liveParentPage->updateSearchContent();
}
}
}
}

0 comments on commit a9e6647

Please sign in to comment.