diff options
Diffstat (limited to 'mod/pages')
-rw-r--r-- | mod/pages/actions/pages/delete.php | 26 | ||||
-rw-r--r-- | mod/pages/start.php | 77 | ||||
-rw-r--r-- | mod/pages/upgrades/2012061800.php | 49 |
3 files changed, 78 insertions, 74 deletions
diff --git a/mod/pages/actions/pages/delete.php b/mod/pages/actions/pages/delete.php index 7a314a280..fd5791e4d 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', + )); + + _elgg_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) { diff --git a/mod/pages/start.php b/mod/pages/start.php index 780d3d9a7..f9c34cd85 100644 --- a/mod/pages/start.php +++ b/mod/pages/start.php @@ -81,11 +81,13 @@ function pages_init() { // entity menu elgg_register_plugin_hook_handler('register', 'menu:entity', 'pages_entity_menu_setup'); - // register ecml views to parse - elgg_register_plugin_hook_handler('get_views', 'ecml', 'pages_ecml_views_hook'); - // hook into annotation menu elgg_register_plugin_hook_handler('register', 'menu:annotation', 'pages_annotation_menu_setup'); + + // register ecml views to parse + elgg_register_plugin_hook_handler('get_views', 'ecml', 'pages_ecml_views_hook'); + + elgg_register_event_handler('upgrade', 'system', 'pages_run_upgrades'); } /** @@ -366,72 +368,3 @@ function pages_ecml_views_hook($hook, $entity_type, $return_value, $params) { return $return_value; } - -/** - * Adds items to "page" annotations menu - * - * @param unknown_type $hook - * @param unknown_type $entity_type - * @param unknown_type $return_value - * @param unknown_type $params - */ -function pages_annotation_menu_setup($hook, $type, $return, $params) { - $annotation = $params['annotation']; - /* @var ElggAnnotation $annotation */ - - $entity = get_entity($annotation->entity_guid); - - if ($annotation->name == 'page' && $entity->canEdit() && $annotation->canEdit()) { - // Get last revision - $revisions = elgg_get_annotations(array( - 'annotation_name' => 'page', - 'limit' => 1, - 'guid' => $annotation->entity_guid, - 'reverse_order_by' => true, - )); - - // Check if this annotation is the last revision - if ($revisions) { - $current_revision = $revisions[0]; - if ($current_revision == $annotation) { - // Don't allow any actions on last revision, just display 'current revision' - $options = array( - 'name' => 'current', - 'href' => false, - 'text' => elgg_echo('pages:current_revision'), - 'encode_text' => false - ); - $return[] = ElggMenuItem::factory($options); - return $return; - } - } - - // Revert - $options = array( - 'name' => 'revert', - 'href' => elgg_http_add_url_query_elements("pages/edit/{$annotation->entity_guid}", array( - 'annotation_id' => $annotation->id - )), - 'text' => elgg_echo('pages:revert'), - 'encode_text' => false - ); - $return[] = ElggMenuItem::factory($options); - - - // Delete - $url = elgg_http_add_url_query_elements('action/annotations/page/delete', array( - 'annotation_id' => $annotation->id, - )); - - $options = array( - 'name' => 'delete', - 'href' => $url, - 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>", - 'confirm' => elgg_echo('deleteconfirm'), - 'encode_text' => false - ); - $return[] = ElggMenuItem::factory($options); - } - - return $return; -} diff --git a/mod/pages/upgrades/2012061800.php b/mod/pages/upgrades/2012061800.php new file mode 100644 index 000000000..c21ccae3b --- /dev/null +++ b/mod/pages/upgrades/2012061800.php @@ -0,0 +1,49 @@ +<?php +/** + * Restore disappeared subpages. This is caused by its parent page being deleted + * when the parent page is a top level page. We take advantage of the fact that + * the parent_guid was deleted for the subpages. + * + * This upgrade script will no longer work once we have converted all pages to + * have the same entity subtype. + */ + + +/** + * Update subtype + * + * @param ElggObject $page + */ +function pages_2012061800($page) { + $dbprefix = elgg_get_config('dbprefix'); + $subtype_id = (int)get_subtype_id('object', 'page_top'); + $page_guid = (int)$page->guid; + update_data("UPDATE {$dbprefix}entities + SET subtype = $subtype_id WHERE guid = $page_guid"); + error_log("called"); + return true; +} + +$previous_access = elgg_set_ignore_access(true); + +$dbprefix = elgg_get_config('dbprefix'); +$name_metastring_id = get_metastring_id('parent_guid'); +if (!$name_metastring_id) { + return; +} + +// Looking for pages without metadata +$options = array( + 'type' => 'object', + 'subtype' => 'page', + 'wheres' => "NOT EXISTS ( + SELECT 1 FROM {$dbprefix}metadata md + WHERE md.entity_guid = e.guid + AND md.name_id = $name_metastring_id)" +); +$batch = new ElggBatch('elgg_get_entities_from_metadata', $options, 'pages_2012061800', 50, false); +elgg_set_ignore_access($previous_access); + +if ($batch->callbackResult) { + error_log("Elgg Pages upgrade (2012061800) succeeded"); +} |