aboutsummaryrefslogtreecommitdiff
path: root/mod/pages/actions/pages/delete.php
blob: ab28e23b63ca4efd5a2e808c720c4484a803d0f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
 * Remove a page
 *
 * @package ElggPages
 */

$page = get_input('page');

if ($page = get_entity($page)) {

	if ($page->canEdit()) {

		$container = get_entity($page->container_guid);

		// Bring all child elements forward
			$parent = $page->parent_guid;
			if ($children = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $page->getGUID()))) {
				foreach($children as $child) {
					$child->parent_guid = $parent;
				}
			}
			if ($page->delete()) {
				system_message(elgg_echo('pages:delete:success'));
				if ($parent) {
					if ($parent = get_entity($parent)) {
						forward($parent->getURL());
					}
				}
				forward("pg/pages/owned/$container->username/");
			}

	}

}

register_error(elgg_echo('pages:delete:failure'));
forward($_SERVER['HTTP_REFERER']);