Skip to content

Commit

Permalink
Merge pull request #23 from PlasticStudio/hotfix/archive-draft-page
Browse files Browse the repository at this point in the history
add condition to check if parent exists
  • Loading branch information
ebakernz authored Feb 12, 2023
2 parents 6a9e821 + a9e6647 commit 929a945
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
Expand Up @@ -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 929a945

Please sign in to comment.