diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index e356a8c252..ea99d50a31 100755 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -3519,7 +3519,7 @@ protected static function flattenTree($tree, $sort_field = null, $sort_order = 1 foreach($tree as $item) { - $children = $item['_children']; + $children = isset($item['_children']) ? $item['_children'] : null; unset($item['_children']); $item['_depth'] = $depth; if($depth > 0) diff --git a/e107_tests/tests/unit/TreeModelTest.php b/e107_tests/tests/unit/TreeModelTest.php index 1fce4cf4ba..e4e4da4f7f 100644 --- a/e107_tests/tests/unit/TreeModelTest.php +++ b/e107_tests/tests/unit/TreeModelTest.php @@ -52,11 +52,11 @@ public function testTreeParentsAreAssignedCorrectly() { $key = $this->sample_key; $parent_key = $this->sample_parent_key; - $l0_id = $this->tree[1][$key]; - $l1_id = $this->tree[1]['_children'][0][$key]; - $l1_parent = $this->tree[1]['_children'][0][$parent_key]; - $l2_id = $this->tree[1]['_children'][0]['_children'][0][$key]; - $l2_parent = $this->tree[1]['_children'][0]['_children'][0][$parent_key]; + $l0_id = $this->tree[0][$key]; + $l1_id = $this->tree[0]['_children'][0][$key]; + $l1_parent = $this->tree[0]['_children'][0][$parent_key]; + $l2_id = $this->tree[0]['_children'][0]['_children'][0][$key]; + $l2_parent = $this->tree[0]['_children'][0]['_children'][0][$parent_key]; $this->assertEquals($l0_id, $l1_parent); $this->assertEquals($l1_id, $l2_parent);