Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Recursive deletion from index if a page is deleted
Browse files Browse the repository at this point in the history
Fixes #8.
  • Loading branch information
lukasbestle committed Aug 25, 2017
1 parent 8f9bb7e commit 933a3ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function algolia() {
});

kirby()->hook('panel.page.delete', function($page) {
return algolia()->deletePage($page);
return algolia()->deletePageRecursive($page);
});

kirby()->hook('panel.page.sort', function($page) {
Expand Down
17 changes: 16 additions & 1 deletion lib/algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public function movePage(Page $oldPage, Page $newPage) {

/**
* Deletes a page from the index
* Used by Panel hooks
*
* @param Page|string $id Kirby page or page ID
*/
Expand All @@ -159,6 +158,22 @@ public function deletePage($id) {
$this->getIndex()->deleteObject($id);
}

/**
* Deletes a page and all its children from the index
* Used by Panel hooks
*
* @param Page|string $page Kirby page or page ID
*/
public function deletePageRecursive($page) {
if(is_string($page)) $page = page($page);
if(!$page) return false;

$this->deletePage($page);
foreach($page->children() as $p) {
$this->deletePageRecursive($p);
}
}

/**
* Checks if a specific page should be included in the Algolia index
* Uses the configuration option algolia.templates
Expand Down

0 comments on commit 933a3ba

Please sign in to comment.