Skip to content

Commit

Permalink
Update PageAlgoliaExtension.php
Browse files Browse the repository at this point in the history
  • Loading branch information
teundirectlease authored Jun 29, 2021
1 parent 79160fd commit a1906bf
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/PageAlgoliaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@ public function onBeforeDelete()
$holder->write();
}
}

/**
* To keep track of the state of our SiteTree, we need to track the unpublished pages so we can remove those from Algolia.
* Before a page gets deleted, create an object holding the ID.
* After write check if the page is archived
*/
public function onBeforeWrite()
public function onAfterWrite()
{
if ($this->owner->isInDb()) {
if(!$this->owner->isPublished()) {
parent::onAfterWrite();
if($this->owner->isArchived()) {
if (DeletedPageAlgoliaObjectIDHolder::get()->filter('AlgoliaObjectID', $this->owner->ID)->count() == 0) {
$holder = DeletedPageAlgoliaObjectIDHolder::create();
$holder->AlgoliaObjectID = $this->owner->ID;
$holder->write();
}
}
}
parent::onBeforeWrite();


}
}

0 comments on commit a1906bf

Please sign in to comment.