Merge pull request #2548 from t3hn0/4.5

BUG Prioritise same-level pages in OldPageRedirector
This commit is contained in:
Robbie Averill 2020-05-11 12:45:55 -07:00 committed by GitHub
commit c58144ad6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,7 +29,10 @@ class OldPageRedirector extends Extension
$getvars = $request->getVars(); $getvars = $request->getVars();
unset($getvars['url']); 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), '/'); $cleanPage = trim(Director::makeRelative($page), '/');
if (!$cleanPage) { if (!$cleanPage) {
$cleanPage = Director::makeRelative(RootURLController::get_homepage_link()); $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) 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; $params = (array)$params;
$URL = rawurlencode(array_shift($params)); $URL = rawurlencode(array_shift($params));
if (empty($URL)) { if (empty($URL)) {
@ -68,9 +71,9 @@ class OldPageRedirector extends Extension
$pages = SiteTree::get()->filter(array( $pages = SiteTree::get()->filter(array(
'URLSegment' => $URL, 'URLSegment' => $URL,
)); ));
if ($parent) { if ($parent || is_numeric($parent)) {
$pages = $pages->filter(array( $pages = $pages->filter(array(
'ParentID' => $parent->ID, 'ParentID' => is_numeric($parent) ? $parent : $parent->ID,
)); ));
} }
/** @var SiteTree $page */ /** @var SiteTree $page */