mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUG Prioritise same-level pages in OldPageRedirector
Added option to pass integer ParentID=0 to OldPageRedirector::find_old_page to ensure search through nested pages from the root of SiteTree structure. Added new call of function and still offering fallback to old behaviour if first call returns false (fixed #2522)
This commit is contained in:
parent
2663db06b5
commit
c92e3b9d79
@ -29,7 +29,10 @@ class OldPageRedirector extends Extension
|
||||
$getvars = $request->getVars();
|
||||
unset($getvars['url']);
|
||||
|
||||
$page = static::find_old_page($params);
|
||||
$page = self::find_old_page($params, 0);
|
||||
if (!$page) {
|
||||
$page = self::find_old_page($params);
|
||||
}
|
||||
$cleanPage = trim(Director::makeRelative($page), '/');
|
||||
if (!$cleanPage) {
|
||||
$cleanPage = Director::makeRelative(RootURLController::get_homepage_link());
|
||||
@ -59,7 +62,7 @@ class OldPageRedirector extends Extension
|
||||
*/
|
||||
public static function find_old_page($params, $parent = null, $redirect = false)
|
||||
{
|
||||
$parent = is_numeric($parent) ? SiteTree::get()->byID($parent) : $parent;
|
||||
$parent = is_numeric($parent) && $parent > 0 ? SiteTree::get()->byID($parent) : $parent;
|
||||
$params = (array)$params;
|
||||
$URL = rawurlencode(array_shift($params));
|
||||
if (empty($URL)) {
|
||||
@ -68,9 +71,9 @@ class OldPageRedirector extends Extension
|
||||
$pages = SiteTree::get()->filter(array(
|
||||
'URLSegment' => $URL,
|
||||
));
|
||||
if ($parent) {
|
||||
if ($parent || is_numeric($parent)) {
|
||||
$pages = $pages->filter(array(
|
||||
'ParentID' => $parent->ID,
|
||||
'ParentID' => is_numeric($parent) ? $parent : $parent->ID,
|
||||
));
|
||||
}
|
||||
/** @var SiteTree $page */
|
||||
|
Loading…
Reference in New Issue
Block a user