ENHANCEMENT Passing through same arguments in SiteTree::get_by_url() than in the wrapped DataObject::get_one()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@69953 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-01-10 07:25:52 +00:00 committed by Sam Minnee
parent 0cd41ac16d
commit 464cd2c129

View File

@ -959,15 +959,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
DataObject::set_context_obj($this); DataObject::set_context_obj($this);
// Ensure URLSegment is unique $idFilter = ($this->ID) ? "`SiteTree`.ID <> '$this->ID'" : '';
$idFilter = ($this->ID)
? " AND `SiteTree`.ID <> '$this->ID'" :
'';
$count = 1; $count = 1;
while ( while (
(class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandler')) || (class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandler')) ||
DataObject::get_one("SiteTree", "URLSegment = '$this->URLSegment' $idFilter") SiteTree::get_by_url($this->URLSegment, $idFilter)
) { ) {
$count++; $count++;
$this->URLSegment = ereg_replace('-[0-9]+$','', $this->URLSegment) . "-$count"; $this->URLSegment = ereg_replace('-[0-9]+$','', $this->URLSegment) . "-$count";
@ -1028,11 +1025,15 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* Return the SiteTree object with the given URL segment. * Return the SiteTree object with the given URL segment.
* *
* @param string $urlSegment The URL segment, eg 'home' * @param string $urlSegment The URL segment, eg 'home'
* * @param string $extraFilter
* @param boolean $cache
* @param string $orderby
* @return SiteTree The object with the given URL segment * @return SiteTree The object with the given URL segment
*/ */
public static function get_by_url($urlSegment) { public static function get_by_url($urlSegment, $extraFilter = "", $cache = true, $orderby = "") {
return DataObject::get_one("SiteTree", "URLSegment = '" . addslashes((string) $urlSegment) . "'"); $filter = sprintf("`SiteTree`.URLSegment = '%s'", Convert::raw2sql($urlSegment));
if($extraFilter) $filter .= " AND $extraFilter";
return DataObject::get_one("SiteTree", $filter, $cache, $orderby);
} }
/** /**