aboutsummaryrefslogtreecommitdiff
path: root/mod/pages/actions/pages/edit.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-07-14 21:42:20 +0200
committerSem <sembrestels@riseup.net>2012-07-14 21:42:20 +0200
commit3bd71fbe0aa4a64021c4c2d59b0782faba8c22b6 (patch)
tree1a3123403eca12fe284442cab6e87fe1b93c5fde /mod/pages/actions/pages/edit.php
parent1d2ce9657a44398646ed1a3980d89a1d2f50fa05 (diff)
downloadelgg-3bd71fbe0aa4a64021c4c2d59b0782faba8c22b6.tar.gz
elgg-3bd71fbe0aa4a64021c4c2d59b0782faba8c22b6.tar.bz2
Refs #1334. Prevent cycles in the pages tree.
Diffstat (limited to 'mod/pages/actions/pages/edit.php')
-rw-r--r--mod/pages/actions/pages/edit.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/mod/pages/actions/pages/edit.php b/mod/pages/actions/pages/edit.php
index e6387c1a4..bf54ae87d 100644
--- a/mod/pages/actions/pages/edit.php
+++ b/mod/pages/actions/pages/edit.php
@@ -70,7 +70,27 @@ if (sizeof($input) > 0) {
// need to add check to make sure user can write to container
$page->container_guid = $container_guid;
-if ($parent_guid) {
+if ($parent_guid && $parent_guid != $page_guid) {
+ // Check if parent isn't below of the page in the tree
+ if ($page_guid) {
+ $tree_page = get_entity($parent_guid);
+ while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) {
+ $tree_page = get_entity($tree_page->parent_guid);
+ }
+ // If is below, bring all child elements forward
+ if ($page_guid == $tree_page->guid) {
+ $previous_parent = $page->parent_guid;
+ $children = elgg_get_entities_from_metadata(array(
+ 'metadata_name' => 'parent_guid',
+ 'metadata_value' => $page->getGUID()
+ ));
+ if ($children) {
+ foreach ($children as $child) {
+ $child->parent_guid = $previous_parent;
+ }
+ }
+ }
+ }
$page->parent_guid = $parent_guid;
}