diff options
author | Cash Costello <cash.costello@gmail.com> | 2013-04-13 06:47:06 -0700 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2013-04-13 06:47:06 -0700 |
commit | 8b53f353c5f4eb5b7c893369142882c856d3c83b (patch) | |
tree | 4d52d280b071dca872f87300461e60eeaf2196e4 /mod/pages/actions | |
parent | d679c1578633a15c91561b1a23c8eee281823a75 (diff) | |
parent | 6dac3f3be526a0fdc2aea05444ed3fe0d4e7bcf5 (diff) | |
download | elgg-8b53f353c5f4eb5b7c893369142882c856d3c83b.tar.gz elgg-8b53f353c5f4eb5b7c893369142882c856d3c83b.tar.bz2 |
Merge pull request #5305 from cash/delete_top_page
Moving sub pages to top pages when parent deleted
Diffstat (limited to 'mod/pages/actions')
-rw-r--r-- | mod/pages/actions/pages/delete.php | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/mod/pages/actions/pages/delete.php b/mod/pages/actions/pages/delete.php index 7a314a280..c99f15fbf 100644 --- a/mod/pages/actions/pages/delete.php +++ b/mod/pages/actions/pages/delete.php @@ -21,11 +21,33 @@ if (elgg_instanceof($page, 'object', 'page') || elgg_instanceof($page, 'object', 'metadata_value' => $page->getGUID() )); if ($children) { + $db_prefix = elgg_get_config('dbprefix'); + $subtype_id = (int)get_subtype_id('object', 'page_top'); + $newentity_cache = is_memcache_available() ? new ElggMemcache('new_entity_cache') : null; + foreach ($children as $child) { - $child->parent_guid = $parent; + if ($parent) { + $child->parent_guid = $parent; + } else { + // If no parent, we need to transform $child to a page_top + $child_guid = (int)$child->guid; + + update_data("UPDATE {$db_prefix}entities + SET subtype = $subtype_id WHERE guid = $child_guid"); + + elgg_delete_metadata(array( + 'guid' => $child_guid, + 'metadata_name' => 'parent_guid', + )); + + invalidate_cache_for_entity($child_guid); + if ($newentity_cache) { + $newentity_cache->delete($child_guid); + } + } } } - + if ($page->delete()) { system_message(elgg_echo('pages:delete:success')); if ($parent) { |