From cb1239e2836b422ed5256c952a9c35ed25236e9a Mon Sep 17 00:00:00 2001 From: Shawn Rice Date: Tue, 8 Aug 2023 09:28:06 -0400 Subject: [PATCH] fix(knowledge): Don't add non-public pages --- .../Knowledge/Listeners/PageCollector.php | 23 ++++++++++++++++++- .../Knowledge/Listeners/RouteCollector.php | 5 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Modules/Knowledge/Listeners/PageCollector.php b/app/Modules/Knowledge/Listeners/PageCollector.php index 8c6ccf1ca..e1e4da53a 100644 --- a/app/Modules/Knowledge/Listeners/PageCollector.php +++ b/app/Modules/Knowledge/Listeners/PageCollector.php @@ -30,7 +30,19 @@ public function subscribe(Dispatcher $events) * @param GenerateSitemap $event * @return void */ - public function handleGenerateSitemap(GenerateSitemap $event) + public function handleGenerateSitemap(GenerateSitemap $event): void + { + $this->pages(0, $event); + } + + /** + * Recursively get pages + * + * @param int $parent_id + * @param GenerateSitemap $event + * @return void + */ + private function pages(int $parent_id, GenerateSitemap $event): void { $p = (new Page)->getTable(); $a = (new Associations)->getTable(); @@ -39,11 +51,18 @@ public function handleGenerateSitemap(GenerateSitemap $event) ->join($a, $a . '.page_id', $p . '.id') ->select($p . '.*', $a . '.level', $a . '.lft', $a . '.rgt', $a . '.id AS assoc_id', $a . '.path AS assoc_path') ->where($a . '.state', '=', 1) + ->whereIn($a . '.access', [1]) + ->where($a . '.parent_id', '=', $parent_id) ->orderBy($a . '.lft', 'asc') ->get(); foreach ($options as $page) { + if ($page->assoc_path == '-separator-') + { + continue; + } + $priority = 0.5; if ($page->level == 0) @@ -66,6 +85,8 @@ public function handleGenerateSitemap(GenerateSitemap $event) ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) ->setPriority($priority) ); + + $this->pages($page->assoc_id, $event); } } } diff --git a/app/Modules/Knowledge/Listeners/RouteCollector.php b/app/Modules/Knowledge/Listeners/RouteCollector.php index 8ef2a5017..cdd894e6f 100644 --- a/app/Modules/Knowledge/Listeners/RouteCollector.php +++ b/app/Modules/Knowledge/Listeners/RouteCollector.php @@ -43,6 +43,11 @@ public function handleCollectingRoutes(CollectingRoutes $event): void foreach ($options as $page) { + if ($page->assoc_path == '-separator-') + { + continue; + } + $indent = str_repeat('|— ', $page->level); $event->addRoute(