From a92b300af8103e4168dc2091e2e8505f756cacf6 Mon Sep 17 00:00:00 2001 From: Sem Date: Tue, 3 Jan 2012 23:22:33 +0100 Subject: Refs #2051. Fixed: ElggEntity's enable does not recurse. --- engine/lib/entities.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index daced6740..d2c86e470 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -1385,12 +1385,15 @@ function disable_entity($guid, $reason = "", $recursive = true) { $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid()); $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities - WHERE container_guid=$guid + WHERE ( + container_guid=$guid or owner_guid=$guid - or site_guid=$guid", 'entity_row_to_elggstar'); + or site_guid=$guid + ) and enabled='yes'", 'entity_row_to_elggstar'); if ($sub_entities) { foreach ($sub_entities as $e) { + add_entity_relationship($e->guid, 'disabled_with', $entity->guid); $e->disable($reason); } } @@ -1446,6 +1449,17 @@ function enable_entity($guid) { $entity->deleteMetadata('disable_reason'); $entity->enableMetadata(); $entity->enableAnnotations(); + + $disabled_with_it = elgg_get_entities_from_relationship(array( + 'relationship' => 'disabled_with', + 'relationship_guid' => $entity->guid, + 'inverse_relationship' => true, + )); + + foreach ($disabled_with_it as $e) { + $e->enable(); + remove_entity_relationship($e->guid, 'disabled_with', $entity->guid); + } return $result; } @@ -2318,3 +2332,4 @@ elgg_register_plugin_hook_handler('volatile', 'metadata', 'volatile_data_export_ /** Register init system event **/ elgg_register_event_handler('init', 'system', 'entities_init'); + -- cgit v1.2.3 From b914774cdf2eabe217c61c9c39805c68af858d98 Mon Sep 17 00:00:00 2001 From: cash Date: Wed, 4 Jan 2012 20:14:33 -0500 Subject: fixed enabling bug, added flag for recursion, removed unnecessary code in disable function --- engine/lib/entities.php | 66 +++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index d2c86e470..48c2e72b8 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -1378,18 +1378,12 @@ function disable_entity($guid, $reason = "", $recursive = true) { } if ($recursive) { - // Temporary token overriding access controls - // @todo Do this better. - static $__RECURSIVE_DELETE_TOKEN; - // Make it slightly harder to guess - $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid()); - - $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities + $sub_entities = get_data("SELECT * FROM {$CONFIG->dbprefix}entities WHERE ( - container_guid=$guid - or owner_guid=$guid - or site_guid=$guid - ) and enabled='yes'", 'entity_row_to_elggstar'); + container_guid = $guid + OR owner_guid = $guid + OR site_guid = $guid + ) AND enabled='yes'", 'entity_row_to_elggstar'); if ($sub_entities) { foreach ($sub_entities as $e) { @@ -1397,18 +1391,14 @@ function disable_entity($guid, $reason = "", $recursive = true) { $e->disable($reason); } } - - $__RECURSIVE_DELETE_TOKEN = null; } $entity->disableMetadata(); $entity->disableAnnotations(); - // relationships can't be disabled. hope they join to the entities table. - //$entity->disableRelationships(); $res = update_data("UPDATE {$CONFIG->dbprefix}entities - set enabled='no' - where guid={$guid}"); + SET enabled = 'no' + WHERE guid = $guid"); return $res; } @@ -1423,51 +1413,51 @@ function disable_entity($guid, $reason = "", $recursive = true) { * @warning In order to enable an entity using ElggEntity::enable(), * you must first use {@link access_show_hidden_entities()}. * - * @param int $guid GUID of entity to enable + * @param int $guid GUID of entity to enable + * @param bool $recursive Recursively enable all entities disabled with the entity? * * @return bool */ -function enable_entity($guid) { +function enable_entity($guid, $recursive = true) { global $CONFIG; $guid = (int)$guid; // Override access only visible entities - $access_status = access_get_show_hidden_status(); + $old_access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); + $result = false; if ($entity = get_entity($guid)) { if (elgg_trigger_event('enable', $entity->type, $entity)) { if ($entity->canEdit()) { - access_show_hidden_entities($access_status); - $result = update_data("UPDATE {$CONFIG->dbprefix}entities - set enabled='yes' - where guid={$guid}"); + SET enabled = 'yes' + WHERE guid = $guid"); $entity->deleteMetadata('disable_reason'); $entity->enableMetadata(); $entity->enableAnnotations(); - - $disabled_with_it = elgg_get_entities_from_relationship(array( - 'relationship' => 'disabled_with', - 'relationship_guid' => $entity->guid, - 'inverse_relationship' => true, - )); - - foreach ($disabled_with_it as $e) { - $e->enable(); - remove_entity_relationship($e->guid, 'disabled_with', $entity->guid); - } - return $result; + if ($recursive) { + $disabled_with_it = elgg_get_entities_from_relationship(array( + 'relationship' => 'disabled_with', + 'relationship_guid' => $entity->guid, + 'inverse_relationship' => true, + )); + + foreach ($disabled_with_it as $e) { + $e->enable(); + remove_entity_relationship($e->guid, 'disabled_with', $entity->guid); + } + } } } } - access_show_hidden_entities($access_status); - return false; + access_show_hidden_entities($old_access_status); + return $result; } /** -- cgit v1.2.3