Skip to content

Commit

Permalink
BUGFIX: Fixed operation of the onlyDeletedFromStage parameter of Hier…
Browse files Browse the repository at this point in the history
…archy::liveChildren().
  • Loading branch information
Sam Minnee committed Feb 8, 2012
1 parent 5a3242c commit d1a39b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions model/Hierarchy.php
Expand Up @@ -562,9 +562,9 @@ public function liveChildren($showAll = false, $onlyDeletedFromStage = false) {
$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', '');

Expand Down
31 changes: 31 additions & 0 deletions tests/model/HierarchyTest.php
Expand Up @@ -119,6 +119,37 @@ function testLoadDescendantIDListIntoArray() {
$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 {
Expand Down

0 comments on commit d1a39b0

Please sign in to comment.