Issue #1051: fix so that OldPageRedirector::find_old_page uses ORM call

This commit is contained in:
Dan Meeking 2014-07-15 22:44:44 -06:00 committed by Daniel Hensby
parent a1286f1c0f
commit 26f5fc2853
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

View File

@ -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;
} }
} }