Example #1
0
 /**
  * Deletes the entity.
  *
  * Removes the entity and its metadata, annotations, relationships,
  * river entries, and private data.
  *
  * Optionally can remove entities contained and owned by this entity.
  *
  * @warning If deleting recursively, this bypasses ownership of items contained by
  * the entity.  That means that if the container_guid = $this->guid, the item will
  * be deleted regardless of who owns it.
  *
  * @param bool $recursive If true (default) then all entities which are
  *                        owned or contained by $this will also be deleted.
  *
  * @return bool
  */
 public function delete($recursive = true)
 {
     $guid = $this->guid;
     if (!$guid) {
         return false;
     }
     // first check if we can delete this entity
     // NOTE: in Elgg <= 1.10.3 this was after the delete event,
     // which could potentially remove some content if the user didn't have access
     if (!$this->canDelete()) {
         return false;
     }
     // now trigger an event to let others know this entity is about to be deleted
     // so they can prevent it or take their own actions
     if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
         return false;
     }
     if ($this instanceof ElggUser) {
         // ban to prevent using the site during delete
         _elgg_services()->usersTable->markBanned($this->guid, true);
     }
     // Delete contained owned and otherwise releated objects (depth first)
     if ($recursive) {
         // Temporarily overriding access controls
         $entity_disable_override = access_get_show_hidden_status();
         access_show_hidden_entities(true);
         $ia = elgg_set_ignore_access(true);
         // @todo there was logic in the original code that ignored
         // entities with owner or container guids of themselves.
         // this should probably be prevented in \ElggEntity instead of checked for here
         $options = array('wheres' => array("((container_guid = {$guid} OR owner_guid = {$guid})" . " AND guid != {$guid})"), 'limit' => 0);
         $batch = new \ElggBatch('elgg_get_entities', $options);
         $batch->setIncrementOffset(false);
         foreach ($batch as $e) {
             $e->delete(true);
         }
         access_show_hidden_entities($entity_disable_override);
         elgg_set_ignore_access($ia);
     }
     $entity_disable_override = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $ia = elgg_set_ignore_access(true);
     // Now delete the entity itself
     $this->deleteMetadata();
     $this->deleteOwnedMetadata();
     $this->deleteAnnotations();
     $this->deleteOwnedAnnotations();
     $this->deleteRelationships();
     $this->deleteAccessCollectionMemberships();
     $this->deleteOwnedAccessCollections();
     access_show_hidden_entities($entity_disable_override);
     elgg_set_ignore_access($ia);
     _elgg_delete_river(array('subject_guid' => $guid));
     _elgg_delete_river(array('object_guid' => $guid));
     _elgg_delete_river(array('target_guid' => $guid));
     remove_all_private_settings($guid);
     _elgg_invalidate_cache_for_entity($guid);
     _elgg_invalidate_memcache_for_entity($guid);
     $dbprefix = elgg_get_config('dbprefix');
     $sql = "\n\t\t\tDELETE FROM {$dbprefix}entities\n\t\t\tWHERE guid = :guid\n\t\t";
     $params = [':guid' => $guid];
     $deleted = $this->getDatabase()->deleteData($sql, $params);
     if ($deleted && in_array($this->type, ['object', 'user', 'group', 'site'])) {
         // delete from type-specific subtable
         $sql = "\n\t\t\t\tDELETE FROM {$dbprefix}{$this->type}s_entity\n\t\t\t\tWHERE guid = :guid\n\t\t\t";
         $this->getDatabase()->deleteData($sql, $params);
     }
     _elgg_clear_entity_files($this);
     return (bool) $deleted;
 }
Example #2
0
$to = get_entity($to);
if (!$from instanceof ElggGroup || !$from->canEdit()) {
    register_error(elgg_echo("subsite_manager:admin:move_group:permission_denied"));
    forward(REFERER);
}
if (!$to instanceof ElggGroup || !$to->canEdit()) {
    register_error(elgg_echo("subsite_manager:admin:move_group:permission_denied"));
    forward(REFERER);
}
if ($from == $to) {
    register_error(elgg_echo("subsite_manager:admin:move_group:from_to_same"));
    forward(REFERER);
}
$submit = get_input("submit");
if (!$submit) {
    forward("/admin/administer_utilities/move_group?preview=true&from={$from->guid}&to={$to->guid}");
}
$dbprefix = elgg_get_config("dbprefix");
$from_acl = $from->group_acl;
$to_acl = $to->group_acl;
$invalidate_entities = get_data("SELECT guid FROM {$dbprefix}entities WHERE container_guid = {$from->guid}");
update_data("UPDATE {$dbprefix}entities SET container_guid = {$to->guid} WHERE container_guid = {$from->guid}");
update_data("UPDATE {$dbprefix}entities SET access_id = {$to_acl} WHERE access_id = {$from_acl}");
update_data("UPDATE {$dbprefix}metadata SET access_id = {$to_acl} WHERE access_id = {$from_acl}");
update_data("UPDATE {$dbprefix}annotations SET access_id = {$to_acl} WHERE access_id = {$from_acl}");
if (is_memcache_available()) {
    foreach ($invalidate_entities as $entity) {
        _elgg_invalidate_memcache_for_entity($entity->guid);
    }
}
system_message(elgg_echo("subsite_manager:admin:move_group:success"));
Example #3
0
 /**
  * Removes user $guid's admin flag.
  *
  * @param int $user_guid User GUID
  * @return bool
  */
 public function removeAdmin($user_guid)
 {
     $user = get_entity($user_guid);
     if (!$user instanceof ElggUser || !$user->canEdit()) {
         return false;
     }
     if (!$this->events->trigger('remove_admin', 'user', $user)) {
         return false;
     }
     $query = "\n\t\t\tUPDATE {$this->table}\n\t\t\tSET admin = 'no'\n\t\t\tWHERE guid = :guid\n\t\t";
     $params = [':guid' => (int) $user_guid];
     _elgg_invalidate_cache_for_entity($user_guid);
     _elgg_invalidate_memcache_for_entity($user_guid);
     if ($this->db->updateData($query, true, $params)) {
         return true;
     }
     return false;
 }
Example #4
0
File: delete.php Project: elgg/elgg
// Bring all child elements forward
$parent = $page->parent_guid;
$children = new ElggBatch('elgg_get_entities_from_metadata', ['metadata_name' => 'parent_guid', 'metadata_value' => $page->guid, 'limit' => 0]);
$db_prefix = elgg_get_config('dbprefix');
$subtype_id = (int) get_subtype_id('object', 'page_top');
foreach ($children as $child) {
    if ($parent) {
        $child->parent_guid = $parent;
        continue;
    }
    // If no parent, we need to transform $child to a page_top
    $child_guid = (int) $child->guid;
    update_data("\n\t\tUPDATE {$db_prefix}entities\n\t\tSET subtype = {$subtype_id}\n\t\tWHERE guid = {$child_guid}\n\t");
    elgg_delete_metadata(array('guid' => $child_guid, 'metadata_name' => 'parent_guid'));
    _elgg_invalidate_cache_for_entity($child_guid);
    _elgg_invalidate_memcache_for_entity($child_guid);
}
if (!$page->delete()) {
    register_error(elgg_echo('pages:delete:failure'));
    forward(REFERER);
}
system_message(elgg_echo('pages:delete:success'));
if ($parent) {
    $parent = get_entity($parent);
    if ($parent) {
        forward($parent->getURL());
    }
}
if (elgg_instanceof($container, 'group')) {
    forward("pages/group/{$container->guid}/all");
} else {
Example #5
0
    error_log("[elgg_copy] Updating dataroot and path");
    update_data("UPDATE {$dbprefix}datalists SET value = '{$dataroot}' where name = 'dataroot'");
    update_data("UPDATE {$dbprefix}datalists SET value = '{$path}' where name = 'path'");
    update_data("UPDATE {$dbprefix}sites_entity SET url = '{$url}' where guid = 1");
    update_data("UPDATE {$dbprefix}metastrings SET string = '{$dataroot}'\nWHERE id = (\n   SELECT value_id\n   FROM {$dbprefix}metadata\n   WHERE name_id = (\n      SELECT *\n      FROM (\n         SELECT id\n         FROM {$dbprefix}metastrings\n         WHERE string = 'filestore::dir_root'\n      ) as ms2\n   )\n   LIMIT 1\n)");
    // turn off https login if necessary
    if (strpos($url, 'https') === false) {
        update_data("UPDATE {$dbprefix}config SET value = 'i:0;' where name = 'https_login'");
    }
}
// Invalidate cache
error_log("[elgg_copy] Invalidating cache");
elgg_invalidate_simplecache();
elgg_reset_system_cache();
_elgg_invalidate_cache_for_entity($elgg_copy_plugin->guid);
_elgg_invalidate_memcache_for_entity($elgg_copy_plugin->guid);
_elgg_disable_caching_for_entity($elgg_copy_plugin->guid);
// unset plugins cache
elgg_set_config('plugins_by_id_map', array());
// regenerate plugin entities
error_log("[elgg_copy] Regenerating plugin entities");
_elgg_generate_plugin_entities();
// Update the sandbox settings
error_log("[elgg_copy] Updating elgg_copy plugin settings");
elgg_set_plugin_setting('master_url', $master_url, PLUGIN_ID);
elgg_set_plugin_setting('master_request_key', $master_request_key, PLUGIN_ID);
elgg_set_plugin_setting('request_key', $key, PLUGIN_ID);
elgg_set_plugin_setting('enable_plugins', $enable_plugins, PLUGIN_ID);
elgg_set_plugin_setting('update_mod', $update_mod, PLUGIN_ID);
elgg_set_plugin_setting('mysqldump_path', $mysqldump_path, PLUGIN_ID);
elgg_set_plugin_setting('update_dataroot', $update_dataroot, PLUGIN_ID);
Example #6
0
 /**
  * Disables all entities owned and contained by a user (or another entity)
  *
  * @param int $owner_guid The owner GUID
  * @return bool
  */
 public function disableEntities($owner_guid)
 {
     $entity = get_entity($owner_guid);
     if (!$entity || !$entity->canEdit()) {
         return false;
     }
     if (!$this->events->trigger('disable', $entity->type, $entity)) {
         return false;
     }
     $query = "\n\t\t\tUPDATE {$this->table}entities\n\t\t\tSET enabled='no'\n\t\t\tWHERE owner_guid = :owner_guid\n\t\t\tOR container_guid = :owner_guid";
     $params = [':owner_guid' => (int) $owner_guid];
     _elgg_invalidate_cache_for_entity($entity->guid);
     _elgg_invalidate_memcache_for_entity($entity->guid);
     if ($this->db->updateData($query, true, $params)) {
         return true;
     }
     return false;
 }