From a1906bf756d6508a95319433041958eb3487db10 Mon Sep 17 00:00:00 2001 From: teundirectlease <73477370+teundirectlease@users.noreply.github.com> Date: Tue, 29 Jun 2021 23:52:08 +0200 Subject: [PATCH] Update PageAlgoliaExtension.php --- src/PageAlgoliaExtension.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/PageAlgoliaExtension.php b/src/PageAlgoliaExtension.php index bab621d..bb9a823 100644 --- a/src/PageAlgoliaExtension.php +++ b/src/PageAlgoliaExtension.php @@ -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(); - - } }