Skip to content

Commit

Permalink
unpublish page, create delete holder to remove algolia object
Browse files Browse the repository at this point in the history
  • Loading branch information
teundirectlease committed Jun 29, 2021
1 parent ae3f84c commit be90ab9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea/
20 changes: 19 additions & 1 deletion src/PageAlgoliaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,23 @@ 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.
*/
public function onBeforeWrite()
{
if ($this->isInDb()) {
if(!$this->isPublished()) {
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 be90ab9

Please sign in to comment.