mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
fafca08c44
commit
8c9b7b282c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user