/** * Make sure all the children are in the correct tree * * @param ElggObject $entity the entity to check the children from * @param int $tree_guid the correct tree guid (will default to the given entity) * * @return bool */ function static_check_children_tree(ElggObject $entity, $tree_guid = 0) { if (!elgg_instanceof($entity, 'object', 'static')) { return false; } $tree_guid = sanitise_int($tree_guid, false); if (empty($tree_guid)) { $tree_guid = $entity->getGUID(); } // ignore access for this part $ia = elgg_set_ignore_access(true); $batch = new ElggBatch('elgg_get_entities', ['type' => 'object', 'subtype' => StaticPage::SUBTYPE, 'owner_guid' => $entity->getOwnerGUID(), 'container_guid' => $entity->getGUID(), 'limit' => false]); foreach ($batch as $static) { // remove old tree remove_entity_relationships($static->getGUID(), 'subpage_of'); // add new tree add_entity_relationship($static->getGUID(), 'subpage_of', $tree_guid); // check children static_check_children_tree($static, $tree_guid); } // restore access elgg_set_ignore_access($ia); return true; }
$relations = $parent->getEntitiesFromRelationship(['type' => 'object', 'subtype' => StaticPage::SUBTYPE, 'relationship' => 'subpage_of', 'limit' => 1]); if ($relations) { $subpage_relationship_guid = $relations[0]->getGUID(); } } if ($subpage_relationship_guid) { // remove old tree relationships remove_entity_relationships($entity->getGUID(), 'subpage_of'); // add new tree relationship $entity->addRelationship($subpage_relationship_guid, 'subpage_of'); } } } // check the children for the correct tree if (!$new_entity) { static_check_children_tree($entity, $subpage_relationship_guid); } $ia = elgg_set_ignore_access(true); // save all the content $entity->title = $title; $entity->description = $description; $entity->access_id = $access_id; $entity->container_guid = $parent_guid; $entity->friendly_title = $friendly_title; $entity->enable_comments = $enable_comments; $entity->moderators = $moderators; $entity->save(); // icon if ($remove_icon) { $entity->removeThumbnail(); } elseif (get_resized_image_from_uploaded_file('thumbnail', 200, 200)) {