FIX so that OldPageRedirector::find_old_page uses ORM call

Cleaning out a TODO item in OldPageRedirector so that we now use ORM syntax to find old versions of pages.
I had no idea ->first also limited. Thanks for the tip!
Fixes for all your notes incoming.


On Wed, Jul 16, 2014 at 2:39 PM, Damian Mooyman <notifications@github.com>
wrote:

> In code/controllers/OldPageRedirector.php:
>
> > -			$query = new SQLQuery (
> > -				'"RecordID"',
> > -				'"SiteTree_versions"',
> > -				"\"URLSegment\" = '$URL' AND \"WasPublished\" = 1" . ($parent ? ' AND "ParentID" = ' . $parent->ID : ''),
> > -				'"LastEdited" DESC',
> > -				null,
> > -				null,
> > -				1
> > -			);
> > -			$record = $query->execute()->first();
> > +			// If we haven't found a candidate, resort to finding a previously published page version with this URL segment
> > +			$oldRecords = DataList::create('SiteTree')
> > +	             ->where("\"URLSegment\" = '$URL'")
> > +	             ->where("\"WasPublished\" = 1")
> > +	             ->sort('"LastEdited" DESC')
> > +	             ->limit(1)
>
> You don't need to limit to 1, since ->first will take care of that.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/silverstripe/silverstripe-cms/pull/1052/files#r15025764>
> .
>