diff --git a/core/control/HTTPRequest.php b/core/control/HTTPRequest.php index 6689a4ae9..6494739e8 100644 --- a/core/control/HTTPRequest.php +++ b/core/control/HTTPRequest.php @@ -330,7 +330,7 @@ class HTTPRequest extends Object implements ArrayAccess { if($varRequired && !isset($this->dirParts[$i])) return false; $arguments[$varName] = isset($this->dirParts[$i]) ? $this->dirParts[$i] : null; - if($part == '$Controller' && !class_exists($arguments['Controller'])) { + if($part == '$Controller' && (!class_exists($arguments['Controller']) || !is_subclass_of($arguments['Controller'], 'RequestHandlingData'))) { return false; } diff --git a/core/model/DataObject.php b/core/model/DataObject.php index d41a39f76..8abb3d4ff 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -2632,7 +2632,7 @@ class DataObject extends ViewableData implements DataObjectInterface { * which could cause horrible bugs. */ public static function set_context_obj($obj) { - if($obj && self::$context_obj) user_error("Dataobject::set_context_obj called when there is already a context.", E_USER_WARNING); + if($obj && self::$context_obj) user_error("Dataobject::set_context_obj passed " . $obj->class . "." . $obj->ID . " when there is already a context: " . self::$context_obj->class . '.' . self::$context_obj->ID, E_USER_WARNING); self::$context_obj = $obj; } diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 867d7780a..ceeb0da56 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -865,7 +865,10 @@ class SiteTree extends DataObject { ''; $count = 1; - while(class_exists($this->URLSegment) || DataObject::get_one("SiteTree", "URLSegment = '$this->URLSegment' $idFilter")) { + while ( + (class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandlingData')) || + DataObject::get_one("SiteTree", "URLSegment = '$this->URLSegment' $idFilter") + ) { $count++; $this->URLSegment = ereg_replace('-[0-9]+$','', $this->URLSegment) . "-$count"; } diff --git a/tests/SiteTreeTest.php b/tests/SiteTreeTest.php index 14f4d8aca..ce9ae4364 100644 --- a/tests/SiteTreeTest.php +++ b/tests/SiteTreeTest.php @@ -12,6 +12,7 @@ class SiteTreeTest extends SapphireTest { * - Turns things into lowercase-hyphen-format * - Generates from Title by default, unless URLSegment is explicitly set * - Resolves duplicates by appending a number + * - renames classes with a class name conflict */ function testURLGeneration() { $expectedURLs = array( @@ -23,6 +24,8 @@ class SiteTreeTest extends SapphireTest { 'product2' => 'another-product', 'product3' => 'another-product-2', 'product4' => 'another-product-3', + 'object' => 'object', + 'controller' => 'controller-2' ); foreach($expectedURLs as $fixture => $urlSegment) { diff --git a/tests/SiteTreeTest.yml b/tests/SiteTreeTest.yml index 29f4caef2..b12141b39 100644 --- a/tests/SiteTreeTest.yml +++ b/tests/SiteTreeTest.yml @@ -23,6 +23,10 @@ Page: Title: Another Product contact: Title: Contact Us + object: + Title: Object + controller: + Title: Controller ErrorPage: 404: