BUGFIX: Fixed extraFilter argument for SiteTree::get_by_url() when translatable is enabled

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@76036 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-04 23:57:12 +00:00
parent fafca08c44
commit 8c9b7b282c
2 changed files with 17 additions and 3 deletions

View File

@ -723,12 +723,13 @@ class Translatable extends DataObjectDecorator {
* @return DataObject
*/
function alternateGetByUrl($urlSegment, $extraFilter, $cache = null, $orderby = null) {
$SQL_URLSegment = Convert::raw2sql($urlSegment);
$filter = sprintf("`SiteTree`.`URLSegment` = '%s'", Convert::raw2sql($urlSegment));
if($extraFilter) $filter .= " AND $extraFilter";
self::$enable_lang_filter = false;
$record = DataObject::get_one('SiteTree', "`URLSegment` = '{$SQL_URLSegment}'");
$record = DataObject::get_one('SiteTree', $filter);
self::$enable_lang_filter = true;
return $record;
}

View File

@ -206,6 +206,19 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals('Page', $requeriedPage->class);
}
/**
* Test SiteTree::get_by_url()
*/
function testGetByURL() {
// Test basic get by url
$this->assertEquals($this->idFromFixture('Page', 'home'), SiteTree::get_by_url("home")->ID);
// Test the extraFilter argument
// Note: One day, it would be more appropriate to return null instead of false for queries such as these
$this->assertFalse(SiteTree::get_by_url("home", "1 = 2"));
}
}
// We make these extend page since that's what all page types are expected to do