Merge pull request #166 from silverstripe-rebelalliance/trac/5239

BUG 5239 Fix infinite loop in some cases w/ live subpage of draft page
This commit is contained in:
Hamish Friedlander 2012-07-22 22:09:07 -07:00
commit 605b11d8d1
2 changed files with 36 additions and 3 deletions

View File

@ -159,7 +159,11 @@ class ModelAsController extends Controller implements NestedController {
'SiteTree',
"\"URLSegment\" = '$URLSegment'" . ($useParentIDFilter ? ' AND "ParentID" = ' . (int)$parentID : '')
);
if($pages && $pages->Count() == 1) return $pages->First();
if($pages && $pages->Count() == 1 && ($page = $pages->First())) {
$parent = $page->ParentID ? $page->Parent() : $page;
if($parent->isPublished()) return $page;
}
}
// Get an old version of a page that has been renamed.
@ -175,8 +179,9 @@ class ModelAsController extends Controller implements NestedController {
$record = $query->execute()->first();
if($record && ($oldPage = DataObject::get_by_id('SiteTree', $record['RecordID']))) {
$oldParent = $oldPage->ParentID ? $oldPage->Parent() : $oldPage;
// Run the page through an extra filter to ensure that all extensions are applied.
if(SiteTree::get_by_link($oldPage->RelativeLink())) return $oldPage;
if(SiteTree::get_by_link($oldPage->RelativeLink()) && $oldParent->isPublished()) return $oldPage;
}
}

View File

@ -234,4 +234,32 @@ class ModelAsControllerTest extends FunctionalTest {
$this->assertEquals(false, $response );
}
/**
* go to a page that's been published but is child of an unpublished page
*
* NOTE: This test requires nested_urls
*/
function testChildOfDraft() {
RootURLController::reset();
SiteTree::enable_nested_urls();
$draft = new Page();
$draft->Title = 'Root Leve Draft Page';
$draft->URLSegment = 'root';
$draft->write();
$published = new Page();
$published->Title = 'Published Page Under Draft Page';
$published->URLSegment = 'sub-root';
$published->write();
$published->publish('Stage', 'Live');
$response = $this->get('root/sub-root');
$this->assertEquals(
$response->getStatusCode(),
404,
'The page should not be found since its parent has not been published, in this case http://<yousitename>/root/sub-root or http://<yousitename>/sub-root'
);
}
}