mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00: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
|
* 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 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
|
* @param boolean $redirect Whether we've found an old page worthy of a redirect
|
||||||
*
|
*
|
||||||
* @return string|boolean False, or the new URL
|
* @return string|boolean False, or the new URL
|
||||||
*/
|
*/
|
||||||
static public function find_old_page($params, $parent = null, $redirect = false) {
|
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;
|
$params = (array)$params;
|
||||||
$URL = rawurlencode(array_shift($params));
|
$URL = rawurlencode(array_shift($params));
|
||||||
if (empty($URL)) { return false; }
|
if (empty($URL)) { return false; }
|
||||||
|
$pages = SiteTree::get()->filter(array(
|
||||||
|
'URLSegment' => $URL,
|
||||||
|
));
|
||||||
if ($parent) {
|
if ($parent) {
|
||||||
$page = SiteTree::get()->filter(array('ParentID' => $parent->ID, 'URLSegment' => $URL))->First();
|
$pages = $pages->filter(array(
|
||||||
} else {
|
'ParentID' => $parent->ID,
|
||||||
$page = SiteTree::get()->filter(array('URLSegment' => $URL))->First();
|
));
|
||||||
}
|
}
|
||||||
|
$page = $pages->first();
|
||||||
|
|
||||||
if (!$page) {
|
if (!$page) {
|
||||||
// If we haven't found a candidate, resort to finding a previously published page version with this URL segment
|
// If we haven't found a candidate, lets resort to finding an old page with this URL segment
|
||||||
$oldRecords = DataList::create('SiteTree')
|
$pages = $pages
|
||||||
->filter(array(
|
->filter(array(
|
||||||
'URLSegment' => $URL,
|
'WasPublished' => true,
|
||||||
'WasPublished' => 1
|
|
||||||
))
|
))
|
||||||
->sort('"LastEdited" DESC')
|
->sort('LastEdited', 'DESC')
|
||||||
->setDataQueryParam("Versioned.mode", 'all_versions');
|
->setDataQueryParam("Versioned.mode", 'all_versions');
|
||||||
|
|
||||||
if($parent) $oldRecords->filter(array('ParentID' => $parent->ID));
|
$record = $pages->first();
|
||||||
|
if ($record) {
|
||||||
$page = $oldRecords->first();
|
$page = SiteTree::get()->byID($record->RecordID);
|
||||||
|
|
||||||
if ($page) {
|
|
||||||
$redirect = true;
|
$redirect = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user