mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
FIX #1052
This commit is contained in:
parent
4aca9ac145
commit
59be597004
@ -38,37 +38,38 @@ class OldPageRedirector extends Extension {
|
||||
* Attempt to find an old/renamed page from some given the URL as an array
|
||||
*
|
||||
* @param array $params The array of URL, e.g. /foo/bar as array('foo', 'bar')
|
||||
* @param SiteTree $parent The current parent in the recursive flow
|
||||
* @param SiteTree|null $parent The current parent in the recursive flow
|
||||
* @param boolean $redirect Whether we've found an old page worthy of a redirect
|
||||
*
|
||||
* @return string|boolean False, or the new URL
|
||||
*/
|
||||
static public function find_old_page($params, $parent = null, $redirect = false) {
|
||||
$parent = is_numeric($parent) ? SiteTree::get()->byId($parent) : $parent;
|
||||
$parent = is_numeric($parent) ? SiteTree::get()->byID($parent) : $parent;
|
||||
$params = (array)$params;
|
||||
$URL = rawurlencode(array_shift($params));
|
||||
if (empty($URL)) { return false; }
|
||||
$pages = SiteTree::get()->filter(array(
|
||||
'URLSegment' => $URL,
|
||||
));
|
||||
if ($parent) {
|
||||
$page = SiteTree::get()->filter(array('ParentID' => $parent->ID, 'URLSegment' => $URL))->First();
|
||||
} else {
|
||||
$page = SiteTree::get()->filter(array('URLSegment' => $URL))->First();
|
||||
$pages = $pages->filter(array(
|
||||
'ParentID' => $parent->ID,
|
||||
));
|
||||
}
|
||||
$page = $pages->first();
|
||||
|
||||
if (!$page) {
|
||||
// If we haven't found a candidate, resort to finding a previously published page version with this URL segment
|
||||
$oldRecords = DataList::create('SiteTree')
|
||||
// If we haven't found a candidate, lets resort to finding an old page with this URL segment
|
||||
$pages = $pages
|
||||
->filter(array(
|
||||
'URLSegment' => $URL,
|
||||
'WasPublished' => 1
|
||||
'WasPublished' => true,
|
||||
))
|
||||
->sort('"LastEdited" DESC')
|
||||
->sort('LastEdited', 'DESC')
|
||||
->setDataQueryParam("Versioned.mode", 'all_versions');
|
||||
|
||||
if($parent) $oldRecords->filter(array('ParentID' => $parent->ID));
|
||||
|
||||
$page = $oldRecords->first();
|
||||
|
||||
if ($page) {
|
||||
$record = $pages->first();
|
||||
if ($record) {
|
||||
$page = SiteTree::get()->byID($record->RecordID);
|
||||
$redirect = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user