Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUGFIX: ticket #5239 - Infinite loop: live subpage of draft page redi…

…rects onto itself when called just by url segment
  • Loading branch information...
commit f7b6f1de5aff8451ab6bb6bc6021036ce70bc0f9 1 parent abc87a4
@cbarberis cbarberis authored hafriedlander committed
View
9 code/controllers/ModelAsController.php
@@ -159,7 +159,11 @@ static function find_old_page($URLSegment,$parentID = 0, $ignoreNestedURLs = fal
'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 @@ static function find_old_page($URLSegment,$parentID = 0, $ignoreNestedURLs = fal
$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
30 tests/controller/ModelAsControllerTest.php
@@ -233,5 +233,33 @@ function testFindOldPage(){
$response = ModelAsController::find_old_page('oldpage2',$page2->ID);
$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'
+ );
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.