]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #1334. Prevent cycles in the pages tree.
authorSem <sembrestels@riseup.net>
Sat, 14 Jul 2012 19:42:20 +0000 (21:42 +0200)
committerSem <sembrestels@riseup.net>
Sat, 14 Jul 2012 19:42:20 +0000 (21:42 +0200)
mod/pages/actions/pages/edit.php
mod/pages/views/default/forms/pages/edit.php

index e6387c1a4e65f9efb0f88d21ec5bea70ec24e5dc..bf54ae87da59d993f77a7b0a84152a09b47423c3 100644 (file)
@@ -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;
 }
 
index 119b9ba2377e2d9e6a0570b0f4eb45e6d46dcc80..583dc414fc50456cb6ab5da224a22cb74e0bb174 100644 (file)
@@ -18,7 +18,8 @@ foreach ($variables as $name => $type) {
        if (($type == 'access' || $type == 'write_access') && !$can_change_access) {
                continue;
        }
-       if ($name == 'parent_guid' && empty($vars['parent_guid'])) {
+       // don't show parent picker input for top or new pages.
+       if ($name == 'parent_guid' && (!$vars['parent_guid'] || !$vars['guid'])) {
                continue;
        }
 ?>