Skip to content

Commit

Permalink
FIX Ensure only live content is indexed via getMainContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
josephlewisnz committed Sep 14, 2023
1 parent b247ccb commit 583e35a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Service/AlgoliaPageCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;
use Throwable;
Expand Down Expand Up @@ -64,6 +65,10 @@ public function getMainContent(): string
$useXpath = false;
$selector = $this->config()->get('content_element_tag');
}

$originalStage = Versioned::get_stage();
//Always set to live to ensure we don't pick up draft content in our render eg. draft elemental blocks
Versioned::set_stage('Live');

// Enable frontend themes in order to correctly render the elements as
// they would be for the frontend
Expand Down Expand Up @@ -117,6 +122,8 @@ public function getMainContent(): string
Requirements::restore();
Config::unnest();

Versioned::set_stage($originalStage);

return $output;
}
}

0 comments on commit 583e35a

Please sign in to comment.