mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Issue #1051: fix so that OldPageRedirector::find_old_page uses ORM call
This commit is contained in:
parent
a1286f1c0f
commit
26f5fc2853
@ -7,7 +7,6 @@ class OldPageRedirector extends Extension {
|
|||||||
* find an old URL that it should be redirecting to.
|
* find an old URL that it should be redirecting to.
|
||||||
*
|
*
|
||||||
* @param SS_HTTPResponse $request The request object
|
* @param SS_HTTPResponse $request The request object
|
||||||
* @throws SS_HTTPResponse_Exception
|
|
||||||
*/
|
*/
|
||||||
public function onBeforeHTTPError404($request) {
|
public function onBeforeHTTPError404($request) {
|
||||||
// Build up the request parameters
|
// Build up the request parameters
|
||||||
@ -48,20 +47,20 @@ class OldPageRedirector extends Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$page) {
|
if (!$page) {
|
||||||
// If we haven't found a candidate, lets resort to finding an old page with this URL segment
|
// If we haven't found a candidate, resort to finding a previously published page version with this URL segment
|
||||||
// TODO: Rewrite using ORM syntax
|
$oldRecords = DataList::create('SiteTree')
|
||||||
$query = new SQLQuery (
|
->filter(array(
|
||||||
'"RecordID"',
|
'URLSegment' => $URL,
|
||||||
'"SiteTree_versions"',
|
'WasPublished' => 1))
|
||||||
"\"URLSegment\" = '$URL' AND \"WasPublished\" = 1" . ($parent ? ' AND "ParentID" = ' . $parent->ID : ''),
|
->sort('"LastEdited" DESC')
|
||||||
'"LastEdited" DESC',
|
->setDataQueryParam("Versioned.mode", 'all_versions');
|
||||||
null,
|
|
||||||
null,
|
if($parent) $oldRecords->filter(array('ParentID' => $parent->ID));
|
||||||
1
|
|
||||||
);
|
$record = $oldRecords->first();
|
||||||
$record = $query->execute()->first();
|
|
||||||
if ($record) {
|
if ($record) {
|
||||||
$page = SiteTree::get()->byID($record['RecordID']);
|
$page = SiteTree::get()->byID($record->RecordID);
|
||||||
$redirect = true;
|
$redirect = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user