BUGFIX: Fixed operation of the onlyDeletedFromStage parameter of Hierarchy::liveChildren().

This commit is contained in:
Sam Minnee 2012-02-08 18:38:37 +13:00
parent 5a3242cab7
commit d1a39b0b1a
2 changed files with 33 additions and 2 deletions

View File

@ -562,9 +562,9 @@ class Hierarchy extends DataExtension {
$children->dataQuery()->setQueryParam('Versioned.stage', 'Live');
if($onlyDeletedFromStage) {
// Note that this makes a second query, and could be optimised to be a joi;
// Note that this makes a second query, and could be optimised to be a join
$stageChildren = DataObject::get($baseClass)
->where("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id");
->where("\"{$baseClass}\".\"ID\" != $id");
$stageChildren->dataQuery()->setQueryParam('Versioned.mode', 'stage');
$stageChildren->dataQuery()->setQueryParam('Versioned.stage', '');

View File

@ -119,6 +119,37 @@ class HierarchyTest extends SapphireTest {
$this->assertEquals(2, count($obj2aIdList));
}
/**
* The "only deleted from stage" argument to liveChildren() should exclude
* any page that has been moved to another location on the stage site
*/
function testLiveChildrenOnlyDeletedFromStage() {
$obj1 = $this->objFromFixture('HierarchyTest_Object', 'obj1');
$obj2 = $this->objFromFixture('HierarchyTest_Object', 'obj2');
$obj2a = $this->objFromFixture('HierarchyTest_Object', 'obj2a');
$obj2b = $this->objFromFixture('HierarchyTest_Object', 'obj2b');
// Get a published set of objects for our fixture
$obj1->publish("Stage", "Live");
$obj2->publish("Stage", "Live");
$obj2a->publish("Stage", "Live");
$obj2b->publish("Stage", "Live");
// Then delete 2a from stage and move 2b to a sub-node of 1.
$obj2a->delete();
$obj2b->ParentID = $obj1->ID;
$obj2b->write();
// Get live children, excluding pages that have been moved on the stage site
$children = $obj2->liveChildren(true, true)->column("Title");
// 2a has been deleted from stage and should be shown
$this->assertContains("Obj 2a", $children);
// 2b has merely been moved to a different parent and so shouldn't be shown
$this->assertNotContains("Obj 2b", $children);
}
}
class HierarchyTest_Object extends DataObject implements TestOnly {