/** * Remove all the files in this folder * * @param \ElggObject $entity the folder to removed the file from * * @return void */ protected static function removeFolderContents(\ElggObject $entity) { $batch = new \ElggBatch('elgg_get_entities_from_relationship', ['type' => 'object', 'subtype' => 'file', 'container_guid' => $entity->getContainerGUID(), 'limit' => false, 'relationship' => FILE_TOOLS_RELATIONSHIP, 'relationship_guid' => $entity->getGUID()]); $batch->setIncrementOffset(false); foreach ($batch as $file) { $file->delete(); } }
public function testCreateWithContainerGuidEqualsZero() { $user = new \ElggUser(); $user->save(); $object = new \ElggObject(); $object->owner_guid = $user->guid; $object->container_guid = 0; // If container_guid attribute is not updated with owner_guid attribute // ElggEntity::getContainerEntity() would return false // thus terminating save() $this->assertTrue($object->save()); $this->assertEqual($user->guid, $object->getContainerGUID()); $user->delete(); }
/** * Change the access of all file in a folder * * @param ElggObject $folder the folder to change the file access for * * @return void */ function file_tools_change_files_access($folder) { if (!empty($folder) && $folder instanceof ElggObject) { if ($folder->getSubtype() == FILE_TOOLS_SUBTYPE) { // change access on files in this folder $options = array("type" => "object", "subtype" => "file", "container_guid" => $folder->getContainerGUID(), "limit" => false, "relationship" => FILE_TOOLS_RELATIONSHIP, "relationship_guid" => $folder->getGUID()); if ($files = elgg_get_entities_from_relationship($options)) { // need to unregister an event listener elgg_unregister_event_handler("update", "object", "file_tools_object_handler"); foreach ($files as $file) { $file->access_id = $folder->access_id; $file->save(); } } } } }
} } // need to add check to make sure user can write to container $page->container_guid = $container_guid; // allow moving of subpages if ($parent_guid && $parent_guid != $page_guid) { // Check if parent isn't below the page in the tree if (!$new_page && $page->parent_guid != $parent_guid) { $tree_page = get_entity($parent_guid); while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->getGUID()) { $tree_page = get_entity($tree_page->parent_guid); } // If is below, bring all child elements forward if ($page_guid == $tree_page->getGUID()) { $previous_parent = (int) $page->parent_guid; $options = array("type" => "object", "subtype" => "page", "container_guid" => $page->getContainerGUID(), "limit" => false, "metadata_name_value_pairs" => array("name" => "parent_guid", "value" => $page->getGUID())); if ($children = elgg_get_entities_from_metadata($options)) { foreach ($children as $child) { $child->parent_guid = $previous_parent; } } } } $page->parent_guid = $parent_guid; } // allow comments $page->allow_comments = $allow_comments; // check for publication/expiration date $publication_date = get_input("publication_date"); $expiration_date = get_input("expiration_date"); // first reset publication status