mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: Replaced usage of the deprecated SiteTree::get_by_url() with get_by_link().
From: Andrew Short <andrewjshort@gmail.com> git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88485 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
57f9a957bc
commit
d4fb917825
@ -56,21 +56,27 @@ class ContentController extends Controller {
|
|||||||
//----------------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------------//
|
||||||
// These flexible data methods remove the need for custom code to do simple stuff
|
// These flexible data methods remove the need for custom code to do simple stuff
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Return the children of the given page.
|
* Return the children of a given page. The parent reference can either be a page link or an ID.
|
||||||
* $parentRef can be a page number or a URLSegment
|
*
|
||||||
|
* @param string|int $parentRef
|
||||||
|
* @return DataObjectSet
|
||||||
*/
|
*/
|
||||||
public function ChildrenOf($parentRef) {
|
public function ChildrenOf($parentRef) {
|
||||||
$SQL_parentRef = Convert::raw2sql($parentRef);
|
$parent = SiteTree::get_by_url($parentRef);
|
||||||
$parent = DataObject::get_one('SiteTree', "\"URLSegment\" = '$SQL_parentRef'");
|
|
||||||
|
if(!$parent && is_numeric($parentRef)) {
|
||||||
|
$parent = DataObject::get_by_id('SiteTree', Convert::raw2sql($parentRef));
|
||||||
|
}
|
||||||
|
|
||||||
if(!$parent && is_numeric($parentRef)) $parent = DataObject::get_by_id('SiteTree', $SQL_parentRef);
|
|
||||||
if($parent) return $parent->Children();
|
if($parent) return $parent->Children();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Page($url) {
|
/**
|
||||||
$SQL_url = Convert::raw2sql($url);
|
* @return DataObjectSet
|
||||||
return DataObject::get_one('SiteTree', "\"URLSegment\" = '$SQL_url'");
|
*/
|
||||||
|
public function Page($link) {
|
||||||
|
return SiteTree::get_by_link($link);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
|
2
core/control/Director.php
Normal file → Executable file
2
core/control/Director.php
Normal file → Executable file
@ -319,7 +319,7 @@ class Director {
|
|||||||
if(isset(Director::$urlParams['URLSegment'])) {
|
if(isset(Director::$urlParams['URLSegment'])) {
|
||||||
$SQL_urlSegment = Convert::raw2sql(Director::$urlParams['URLSegment']);
|
$SQL_urlSegment = Convert::raw2sql(Director::$urlParams['URLSegment']);
|
||||||
|
|
||||||
return SiteTree::get_by_url($SQL_urlSegment);
|
return SiteTree::get_by_link($SQL_urlSegment);
|
||||||
} else {
|
} else {
|
||||||
return Controller::curr();
|
return Controller::curr();
|
||||||
}
|
}
|
||||||
|
4
core/control/ModelAsController.php
Normal file → Executable file
4
core/control/ModelAsController.php
Normal file → Executable file
@ -60,7 +60,7 @@ class ModelAsController extends Controller implements NestedController {
|
|||||||
public function getNestedController() {
|
public function getNestedController() {
|
||||||
if($this->urlParams['URLSegment']) {
|
if($this->urlParams['URLSegment']) {
|
||||||
$SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
|
$SQL_URLSegment = Convert::raw2sql($this->urlParams['URLSegment']);
|
||||||
$child = SiteTree::get_by_url($SQL_URLSegment);
|
$child = SiteTree::get_by_link($SQL_URLSegment);
|
||||||
if(!$child) {
|
if(!$child) {
|
||||||
if($child = $this->findOldPage($SQL_URLSegment)) {
|
if($child = $this->findOldPage($SQL_URLSegment)) {
|
||||||
$url = Controller::join_links(
|
$url = Controller::join_links(
|
||||||
@ -131,7 +131,7 @@ class ModelAsController extends Controller implements NestedController {
|
|||||||
if($redirectObj) {
|
if($redirectObj) {
|
||||||
// Double-check by querying this page in the same way that getNestedController() does. This
|
// Double-check by querying this page in the same way that getNestedController() does. This
|
||||||
// will prevent query muck-ups from modules such as subsites
|
// will prevent query muck-ups from modules such as subsites
|
||||||
$doubleCheck = SiteTree::get_by_url($redirectObj->URLSegment);
|
$doubleCheck = SiteTree::get_by_link($redirectObj->URLSegment);
|
||||||
if($doubleCheck) return $redirectObj;
|
if($doubleCheck) return $redirectObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1344,7 +1344,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
// Ensure URLSegment is unique
|
// Ensure URLSegment is unique
|
||||||
$count = 1;
|
$count = 1;
|
||||||
$otherpage = false;
|
$otherpage = false;
|
||||||
while((class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandler')) || $otherpage = SiteTree::get_by_url($this->URLSegment)) {
|
while((class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandler')) || $otherpage = SiteTree::get_by_link($this->URLSegment)) {
|
||||||
if($otherpage && $otherpage->ID == $this->ID) {
|
if($otherpage && $otherpage->ID == $this->ID) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ class DataObjectTest extends SapphireTest {
|
|||||||
* - Limit
|
* - Limit
|
||||||
* - Container class
|
* - Container class
|
||||||
* - DataObject::get_by_id()
|
* - DataObject::get_by_id()
|
||||||
* - DataObject::get_by_url()
|
|
||||||
* - DataObject::get_one()
|
* - DataObject::get_one()
|
||||||
* - With and without caching
|
* - With and without caching
|
||||||
* - With and without ordering
|
* - With and without ordering
|
||||||
@ -98,10 +97,6 @@ class DataObjectTest extends SapphireTest {
|
|||||||
$page = DataObject::get_by_id('Page', $homepageID);
|
$page = DataObject::get_by_id('Page', $homepageID);
|
||||||
$this->assertEquals('Home', $page->Title);
|
$this->assertEquals('Home', $page->Title);
|
||||||
|
|
||||||
// Test get_by_url()
|
|
||||||
$page = SiteTree::get_by_url('home');
|
|
||||||
$this->assertEquals($homepageID, $page->ID);
|
|
||||||
|
|
||||||
// Test get_one() without caching
|
// Test get_one() without caching
|
||||||
$comment1 = DataObject::get_one('PageComment', "\"Name\"='Joe'", false);
|
$comment1 = DataObject::get_one('PageComment', "\"Name\"='Joe'", false);
|
||||||
$comment1->Comment = "Something Else";
|
$comment1->Comment = "Something Else";
|
||||||
|
Loading…
Reference in New Issue
Block a user