Skip to content
This repository
Browse code

BUGFIX: Fixed operation of the onlyDeletedFromStage parameter of Hier…

…archy::liveChildren().
  • Loading branch information...
commit d1a39b0b1a0aefeedc9f207e071e8bde1cb418eb 1 parent 5a3242c
Sam Minnée authored February 08, 2012
4  model/Hierarchy.php
@@ -562,9 +562,9 @@ public function liveChildren($showAll = false, $onlyDeletedFromStage = false) {
562 562
 		$children->dataQuery()->setQueryParam('Versioned.stage', 'Live');
563 563
 		
564 564
 		if($onlyDeletedFromStage) {
565  
-			// Note that this makes a second query, and could be optimised to be a joi;
  565
+			// Note that this makes a second query, and could be optimised to be a join
566 566
 			$stageChildren = DataObject::get($baseClass)
567  
-				->where("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id");
  567
+				->where("\"{$baseClass}\".\"ID\" != $id");
568 568
 			$stageChildren->dataQuery()->setQueryParam('Versioned.mode', 'stage');
569 569
 			$stageChildren->dataQuery()->setQueryParam('Versioned.stage', '');
570 570
 			
31  tests/model/HierarchyTest.php
@@ -119,6 +119,37 @@ function testLoadDescendantIDListIntoArray() {
119 119
 		$this->assertEquals(2, count($obj2aIdList));
120 120
 	}
121 121
 
  122
+	/**
  123
+	 * The "only deleted from stage" argument to liveChildren() should exclude
  124
+	 * any page that has been moved to another location on the stage site
  125
+	 */
  126
+	function testLiveChildrenOnlyDeletedFromStage() {
  127
+		$obj1 = $this->objFromFixture('HierarchyTest_Object', 'obj1');
  128
+		$obj2 = $this->objFromFixture('HierarchyTest_Object', 'obj2');
  129
+		$obj2a = $this->objFromFixture('HierarchyTest_Object', 'obj2a');
  130
+		$obj2b = $this->objFromFixture('HierarchyTest_Object', 'obj2b');
  131
+
  132
+		// Get a published set of objects for our fixture
  133
+		$obj1->publish("Stage", "Live");
  134
+		$obj2->publish("Stage", "Live");
  135
+		$obj2a->publish("Stage", "Live");
  136
+		$obj2b->publish("Stage", "Live");
  137
+		
  138
+		// Then delete 2a from stage and move 2b to a sub-node of 1.
  139
+		$obj2a->delete();
  140
+		$obj2b->ParentID = $obj1->ID;
  141
+		$obj2b->write();
  142
+
  143
+		// Get live children, excluding pages that have been moved on the stage site
  144
+		$children = $obj2->liveChildren(true, true)->column("Title");
  145
+		
  146
+		// 2a has been deleted from stage and should be shown
  147
+		$this->assertContains("Obj 2a", $children);
  148
+		
  149
+		// 2b has merely been moved to a different parent and so shouldn't be shown
  150
+		$this->assertNotContains("Obj 2b", $children);
  151
+	}
  152
+
122 153
 }
123 154
 
124 155
 class HierarchyTest_Object extends DataObject implements TestOnly {

0 notes on commit d1a39b0

Please sign in to comment.
Something went wrong with that request. Please try again.