Skip to content

Commit

Permalink
Merge pull request #65 from josephlewisnz/fix/draft-content-indexed
Browse files Browse the repository at this point in the history
FIX Ensure only live content is indexed via getMainContent()
  • Loading branch information
wilr authored Sep 15, 2023
2 parents b247ccb + bfdda19 commit 6e7739a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8",
"symbiote/silverstripe-queuedjobs": "^5",
"symbiote/silverstripe-queuedjobs": "^4 || ^5",
"algolia/algoliasearch-client-php": "^3",
"ramsey/uuid": "^4",
"masterminds/html5": "^2.7"
Expand Down
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(Versioned::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 6e7739a

Please sign in to comment.