From b5d8a91e49f804d94e8dc2a619002f3212d000a8 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 20 Feb 2024 11:08:58 -0500 Subject: [PATCH] Fix issue processwire/processwire-issues#1882 --- wire/modules/PagePathHistory.module | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/wire/modules/PagePathHistory.module b/wire/modules/PagePathHistory.module index 1bf65bd5..1ffdeeaa 100644 --- a/wire/modules/PagePathHistory.module +++ b/wire/modules/PagePathHistory.module @@ -389,7 +389,6 @@ class PagePathHistory extends WireData implements Module, ConfigurableModule { * @param Page $page * @param string|array $path * @param array $options - * * @return array * */ @@ -459,6 +458,13 @@ class PagePathHistory extends WireData implements Module, ConfigurableModule { * */ protected function getVirtualHistoryParent(Page $page, $pageName, array $pagePathInfo, Page $parent, array $options) { + + static $levels = array(); + + // prevent duplicate recursive calls + $levelKey = "$page->id!$pageName"; + if(isset($levels[$levelKey])) return array(); + $levels[$levelKey] = true; $paths = array(); @@ -479,7 +485,16 @@ class PagePathHistory extends WireData implements Module, ConfigurableModule { foreach($pageNamesDates as $name => $date) { // iterate through all possible parent paths - foreach($parentPaths as $parentPathInfo) { + foreach($parentPaths as $parentPathKey => $parentPathInfo) { + + /* + * @todo determine if this should be applied + if(strpos($parentPathInfo['path'], $pagePathInfo['path']) === 0) { + // disallow URLs where parent URL is child of page that has the parent + unset($parentPaths[$parentPathKey]); + continue; + } + */ $parentPath = $options['verbose'] ? $parentPathInfo['path'] : $parentPathInfo; @@ -519,6 +534,8 @@ class PagePathHistory extends WireData implements Module, ConfigurableModule { } } + unset($levels[$levelKey]); + return $paths; }