aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/entities.php
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2012-01-25 21:46:20 -0800
committerBrett Profitt <brett.profitt@gmail.com>2012-01-25 21:46:20 -0800
commit4202d7d3087db4f503a7586a1f3fc824ebf45b30 (patch)
tree5c120eb9080425569f322668e1896becd9fb5e5c /engine/lib/entities.php
parent6a2d3d7c2d22f57f28472d9d023788d20d41f005 (diff)
downloadelgg-4202d7d3087db4f503a7586a1f3fc824ebf45b30.tar.gz
elgg-4202d7d3087db4f503a7586a1f3fc824ebf45b30.tar.bz2
Fixes #4081. Using ElggBatch to delete recursive.
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r--engine/lib/entities.php28
1 files changed, 16 insertions, 12 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 2dc0eb8ae..c1ef683e5 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1520,18 +1520,22 @@ function delete_entity($guid, $recursive = true) {
$entity_disable_override = access_get_show_hidden_status();
access_show_hidden_entities(true);
$ia = elgg_set_ignore_access(true);
- $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities
- WHERE container_guid=$guid
- or owner_guid=$guid
- or site_guid=$guid", 'entity_row_to_elggstar');
- if ($sub_entities) {
- foreach ($sub_entities as $e) {
- // check for equality so that an entity that is its own
- // owner or container does not cause infinite loop
- if ($e->guid != $guid) {
- $e->delete(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 OR site_guid = $guid)"
+ . " AND guid != $guid)"
+ ),
+ 'limit' => 0
+ );
+
+ $batch = new ElggBatch('elgg_get_entities', $options, 50, false);
+
+ foreach ($batch as $e) {
+ $e->delete(true);
}
access_show_hidden_entities($entity_disable_override);